How do you find gameobject in array?

Hello,

I would like to know how do you find gameobject in array?

for example I have multiple target in my array I would like to get the gameobject from array and used it.

thank you.

If you know the index number of the object, for example if the index number is 5:

object = myArray[5];

Here is how to find an object by name (untested):

var myArray : Array = new Array();

function FindGameObject (nameYourLookingFor : String) {

        for (var i : int; i < myArray.length; i++) {
                 if (myArray[i].name == nameYourLookingFor) {
                          return myArray[i];
                 }
        }

}

Then simply call FindGameObject().

Although you should be careful of using this, as it isn’t the fastest thing in the world. Use it sparsely, basically.

Thank you, will try this out later.