x


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?

more ▼

asked Dec 01 '10 at 11:09 PM

oliver-jones gravatar image

oliver-jones
2.5k 205 225 253

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
}
more ▼

answered Dec 01 '10 at 11:44 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x418
x407
x275
x183
x48

asked: Dec 01 '10 at 11:09 PM

Seen: 1278 times

Last Updated: Dec 01 '10 at 11:09 PM