- Home /
The question is answered, right answer was accepted
Deactivate gameobject and all children
I there any way in C# that you can deactivate a game object and all its children. I have a game object that has like 25 children I want to deactivate that gameobject and all of its children.
Answer by flaviusxvii · Nov 26, 2012 at 11:06 PM
I get this Error. error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `SetActive' and no extension method `SetActive' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
Are you using an older version of Unity? You used to just set gameObject.active = false. Or whatever you needed to do. That's deprecated in Unity 4.
The Unity3 equivalent is gameObject.SetActiveRecursively(true or false)
Ok thanks so much your bottom commet is what I was needing.
Answer by sparkzbarca · Nov 26, 2012 at 11:50 PM
the parent transform contains an implicit list of children.
foreach (transform child in parent.transform) { child.gameobject.enable = false; }
Thats the most elegant way i think.
Mark as answered :)
Except GameObject doesn't have an "enable" datamember.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Activating/Deactivating GameObject Problem :( 3 Answers
How do I call an animation event on a deactivated gameobject in unity3d c# 0 Answers
How to activate/deactivate a component(Animator) when a specific game object was activated 0 Answers
Distribute terrain in zones 3 Answers