Hi guys
need help on how to deactivate the objects which are parented under an empty game object through a script.
thankyou all in advance
Hi guys
need help on how to deactivate the objects which are parented under an empty game object through a script.
thankyou all in advance
Well if you are looking at turning them off you could do something like,
foreach(Transform t in gameObject.GetComponentsInChildren(typeof(Transform)))
{
t.active = false;
}
where the gameObject is the root (empty object) you want to use. If you are looking for the ability to turn them on and off, you will either have to save the components in an array using GetComponentsInChildren and iterate over that, or just turn off the renderer (and/or colliders) instead.
Alternatively, keep a reference to the empty game object and just disable that one if you want to disable all childs anyway and the game object itself is just a “management dummy”