Search Unity

Question Destroy an object forever when a mission is activated

Discussion in 'Documentation' started by Arni976, Oct 28, 2021.

  1. Arni976

    Arni976

    Joined:
    Sep 25, 2021
    Posts:
    1
    hi guys, i have a doubt im trying to destroy an object when an other object is activated in the hierachy.
    i mean, im blocking the pass with a few trees the when the player activates de second mission i want to destroy that trees to let the player move ahead, but it doesnt work well. When the second mision is activated it destroiees de trees but if i change de scene and the i go back the trees are there again.

    i made this:
    public class GTFO : MonoBehaviour
    {
    public GameObject mision2;
    public GameObject d1, d2;
    // Update is called once per frame
    void Update()
    {
    if (mision2.activeInHierarchy)
    {
    //Destroy(d1);
    //Destroy(d2);
    d1.SetActive(false);
    d2.SetActive(false);
    }
    }
    }

    i was trying different options but it doesnt work. I learing as you can see. Ty for the help.