x


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.

more ▼

asked Jul 17 '11 at 11:38 PM

Syllith gravatar image

Syllith
44 9 10 13

What you want is the amazing SetActiveRecursively command ... check it out in the manual

Oct 21 '11 at 05:25 PM Fattie
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

This is as simple as using GetComponent*s*InChildren() and then going through the array as needed.


var renderers : Renderer[] = GetComponentsInChildren.< Renderer >();//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

more ▼

answered Jul 18 '11 at 12:02 AM

SilverTabby gravatar image

SilverTabby
1.9k 3 6 18

(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:

x1359
x410
x275
x133
x21

asked: Jul 17 '11 at 11:38 PM

Seen: 2095 times

Last Updated: Oct 21 '11 at 05:26 PM