- Home /
Question by
chillypacman · Oct 22, 2011 at 09:18 AM ·
c#activegame-object
Is there a quick way to de-activate a game object and all its children in script?
Basically from script, I can set active to false for a game object, but can I do it in sucha way that all its children also get de-activated?
Iterating through children is cumbersome and involves al ot of duplicate code...
Comment
Be sure to tick and vote for Aldona's awesome and fast answer!
Best Answer
Answer by aldonaletto · Oct 22, 2011 at 09:28 AM
You can use SetActiveRecursively, like this:
gameObject.SetActiveRecursively(false); // deactivate this object and children
If it's other object, just use its GameObject reference:
var other: GameObject;
other.SetActiveRecursively(true); // activate "other" and its children