- Home /
check where a game object is in an array
I have an array of GameObjects and I have a GameObject variable how do I check what number the GameObject variable is in the array?
Answer by aldonaletto · Jun 01, 2012 at 12:41 AM
If it's a built-in array (GameObject[]), the only way I know is to compare each element like this:
var goArray: GameObject[];
function ObjectIndex(myObj: GameObject): int { for (var ix = 0; ix < goArray.lenght; ix++){ if (goArray[ix] == myObj) return ix; } return -1; } This function will return the object index, or -1 if not found.
how would I call it if it was var number : int = ObjectIndex()?
Your answer
![](https://koobas.hobune.stream/wayback/20220613072221im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to remove objects from a list ? 3 Answers
Can't add GameObjects to ArrayList 1 Answer
How do I check multiple gameObjects transform positions? 3 Answers
Array Help GameObject Length Inventory 1 Answer
Making a button from a list of arrays. 0 Answers