go trough all attached objects with a for loop

hi there

working on a pinball game i encounter the following problem:

got a trigger in the sceen that fires a message to an object pyroholder when it was hit - in order to get a visual effect there - this works fine as long i use just one pyroholder

when i duplicate that pyroholder i still have the effect just once…

i think that’s because it fires when the first is found and is not looking for other attached objects.

I asume i’ll have to do a for loop in order to go to the number of n-objects

my code is:

function OnTriggerEnter(ground:Collider) {

print (“pyro”); //particleEmitter.Emit=true;

transform.Find(“pyroHolder”).SendMessage (“Pyro”);
}

how can i go trough all attached objects?

1 Answer

1

Thats simple

for (var child : Transform in this.transform)
{
  // do xy
}

or if you don’t want the transforms but a specific monobehaviour or component, then it’s FindComponentsInChildren<ClassName> () (or FindComponentsInChildren.<ClassName> () for unityscript)