How can you use GameObject.Find() to find multiple objects in a scene with the same name? Is there a better way to iterate through and find all my prefabs?
There is actually a couple of ways to deal with this problem. My recommendation would be to tag all of the game objects and use:
var objects = GameObject.FindGameObjectsWithTag ("MyGameObject");
In the above code, the objects array will hold all of the GameObjects with a specific tag.
Another way to do this would be to get all of you GameObjects in an array, and iterate through them to find GameObjects of a certain name:
var objects = FindObjectsOfType (GameObject);
for (var object : GameObject in objects) {
if (object.name == "MyGameObject") {
DoSomething();
}
}
If they all have a parent object in common, you can iterate through them using their transform properties. See the example at the top of the Transform class doc page for details.