unity enable and disable gameobject 1

unity enable and disable gameobject

public GameObject gameObj;//the gameobject you want to disable in the scene

        gameObj.SetActive(true); //set the object to active
        gameObj.SetActive(false);//set the object to disable

        gameObject.SetActive(true);//change the state of the current gameobject to active
        gameObject.SetActive(false);//change the state of the current gameobject to disable

Here is what the above code is Doing:
1. We are creating a variable called gameObj and we are assigning it to a gameobject in the scene.
2. We are setting the gameObj to active.
3. We are setting the gameObj to disable.
4. We are setting the current gameobject to active.
5. We are setting the current gameobject to disable.

Similar Posts