- Home /
Disable multiple child components
I've checked online but couldn't find much help. I'm making a FPS and he's going to have multiple guns. To switch weapons, I want to animate him putting it away, then disable the renderers for all the children components rather than copy and pasting about 20 times, turning off each part of the gun and arm manually. Is there a way I can simply turn off the renderers for all the child components of a game object? I know it will have something to do with GetComponentInChildren, but I'm still not sure. Thanks for any help.
What you want is the amazing SetActiveRecursively command ... check it out in the manual
Answer by SilverTabby · Jul 18, 2011 at 12:02 AM
This is as simple as using GetComponent**s**InChildren() and then going through the array as needed.
var renderers : Renderer[] = GetComponentsInChildren.();//you need to remove the spaces inside the
and then disable the renderers as needed using a for loop or a for-each loop.
The FPS tutorial uses a similar method of switching weapons.
Hope this helped