Hello.
I made a GUI with some GameObjects, but they are active, or in other words, they are visible when i start up the game. I want them to be invisible by default when i start up the game, but i cannot figure out where to do that in the code? Any help?
Here is my code
public GameObject[] objects;
private void OnGUI()
{
foreach (GameObject go in objects)
{
bool active = GUILayout.Toggle(go.activeSelf, go.name);
if (active != go.activeSelf)
{
go.SetActive(active);
}
}
}
See the checkbox next to the name of the object? If you uncheck it the object will start off disabled.
Be aware that this method doesn’t have anything to do with the current UI (the one where you place components within the Scene View). It’s intended to be used to create custom editors for the Inspector.