Search Unity

How to delete the gameObject with in prefab Instance and then apply by code?

Discussion in 'Prefabs' started by Bagazi, Jul 20, 2021.

  1. Bagazi

    Bagazi

    Joined:
    Apr 18, 2018
    Posts:
    611
    upload_2021-7-20_17-32-27.png

    In my case , I want to delete the mousepad01 object from the parent (which is a prefab instance ) by code and then apply it.. Is that possible?
     
  2. ZingZangGames

    ZingZangGames

    Joined:
    Dec 11, 2020
    Posts:
    73
    You can delete it by creating a new script and then assigning it to the prefab master (the parent that parents everything in the prefab.)
    In the script, do this:

    Code (CSharp):
    1. public void deleteObject(GameObject obj, float wait)
    2. {
    3.    // Obj: The object that you want to delete
    4.    // wait: After how many seconds the object is deleted after
    5.    // calling this method
    6.    GameObject.Destroy(obj, wait);
    7. }
    Call this function and you should be fine. I don't understand what you mean by "apply".
    Hope this helps!
     
    iroxyn likes this.
  3. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Bagazi likes this.