Answers for "disable or enable gameobject unity"

C#
21

how to disable a gameObject unity c#

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
Posted by: Guest on May-23-2020
0

unity enable gameobject

// Drag & Drop the gameobject in the inspector
 public GameObject targetGameObject ;

 public void DisableGameObject()
 {
      targetGameObject.SetActive( false ) ;
 }

 public void EnableGameObject()
 {
      targetGameObject.SetActive( true ) ;
 }

 public void ToggleGameObject()
 {
      if( targetGameObject.activeSelf )
           DisableGameObject() ;
      else
           EnableGameObject();
 }
Posted by: Guest on March-07-2022

Code answers related to "disable or enable gameobject unity"

C# Answers by Framework

Browse Popular Code Answers by Language