GetComponent of ALL clones?

How do I get the component of all the clones of my object?

When I use

box = GameObject.Find("Box").GetComponents();

It only gets the component of the first box he somewhat finds, but ignores the other clones of the boxes.

I also couldn’t just use a static variable, since I have another script that only needs to get one component, and when I get the component of the script, its static variables doesn’t work for some reason.

Thanks! Simple question, but couldn’t find it at all in Google or in Unity Answers.

You can only get specific type of components in your scene. You can get all AudioSources or Colliders:

A workaround for your situation might be as follows.
Make a tag specific to that object group and tag them all the same.
Then create a GameObject array, and then assign all game objects to this array using

yourObjects = GameObject.FindGameObjectsWithTag ("Your Tag");

Then you can get each of their component like this:


Use FIndObjectsOfType

This and many other wonder can be found in the docs…