- Home /
C# SetActive GameObject Array
Hi everyone, I have a GameObject Array that I would like to have it's SetActive set to false.But how I do that since arrays don't have a definition for SetActive?
Answer by flamy · Jun 29, 2013 at 07:30 PM
foreach(GameObject _obj in gameObjectArray)
{
_obj.SetActive(false);
}
there is no direct method to do that. This is the only way.
Correct. You can access each gameObject in the array with a foreach statement. This statement shown disables ALL instances of _obj in the array. +1
how can you reenable the deactivated items ? _obj.SetActive(true); does not seem to work
@trelobyte, you should post this as a new question with a link to this one. Anyway, SetActive(true) is the right way to reactivate the object - but be aware that in Unity 4 the object will remain deactivated if its parent is inactive (see GameObject.SetActive)
Answer by newmaker · Mar 09, 2017 at 08:27 AM
@trelobyte, if you have OnTriggerEnter, try copy the same code in this function into the OnTriggerExit function and then set it to set.Active(false); this should work.
Your answer
Follow this Question
Related Questions
C# Check If Scripted Gameobject goes Past Variable Gameobject 0 Answers
C# Specifying which Children to add to the Array 1 Answer
C# Make Child Not Animate Looped Animation 1 Answer
C# GameObjectList not Setting Parent 0 Answers
C# Gameobject's Script's ValuesEquals Other Gameobject's script's Values 1 Answer