- Home /
Deactivate Specific Children In Partent
Hello,
I have a game object with meny children. And right now I use this script to turn off all the children.
But is it possible to turn off specific children (im using renderer to deactivate):
var renderers = GetComponentsInChildren(Renderer);
for (var r : Renderer in renderers) {
r.enabled = false;
}
So if my children were names:
Child1 Child2 Child3
How would I turn off all children except Child2?
Comment
Best Answer
Answer by Mike 3 · Dec 01, 2010 at 11:44 PM
You could just check the name of the current object in the loop:
var renderers = GetComponentsInChildren(Renderer);
for (var r : Renderer in renderers) {
if (r.name != "Child2") r.enabled = false;
}
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Create multiple instances of an object 2 Answers
Constraining an object's movement using two spring joints on its children 1 Answer
Update Parent/ Children From Script? 2 Answers
find ALL children of a parent 1 Answer