Question by
luizarruda · Oct 21, 2015 at 10:29 PM ·
javascriptguigameobject
GameObject deactivate but don't activate again
Hi, the GameObjects deactivate correctly, but after I deactivate them, they don't activate again. Anyone?
function OnGUI () {
GUI.Box (Rect (10,10,100,90), "LOD Menu");
if (GUI.Button (Rect (20,40,80,20), "LOD100")) {
for(var lod400 : GameObject in GameObject.FindGameObjectsWithTag("LOD400"))
{
lod400.active = false;
}
for(var lod100 : GameObject in GameObject.FindGameObjectsWithTag("LOD100"))
{
lod100.active = true;
}
}
if (GUI.Button (Rect (20,70,80,20), "LOD400")) {
for(var lod400 : GameObject in GameObject.FindGameObjectsWithTag("LOD400"))
{
lod400.active = true;
}
for(var lod100 : GameObject in GameObject.FindGameObjectsWithTag("LOD100"))
{
lod100.active = false;
}
}
}
Comment
Answer by dkjunior · Oct 21, 2015 at 11:57 PM
FindGameObjectsWithTag doesn't return inactive objects. I recommend to save references to all objects you need to activate/inactivate in an array/list and operate on them.