disable a gameobject in csharp

To disable a GameObject in C#, you can simply set its active property to false. Here's an example:

main.cs
// Get the GameObject you want to disable
GameObject myObject = GameObject.Find("MyObject");

// Disable the GameObject
myObject.SetActive(false);
147 chars
6 lines

In this example, we first find the GameObject we want to disable using the GameObject.Find method. Then, we call the SetActive method on the GameObject and pass in false as the parameter. This will disable the GameObject and make it invisible and inactive in the scene.

gistlibby LogSnag