How do I know where a randomly selected object is in an array?

I’ve set up a 2d array of gameobjects[x,y]

The player selects one of these objects in the game world eg. raycast/mouseclick

How do I know which x,y position in the array the selected object is?

I need to know as I have a second array I want to cross-reference.

please halp! :wink:

Unfortunately there’s no built-in method for 2D arrays like IndexOf.

What you can do is basically 2 things:

  1. Which I personally favorite, is to store on each game object it’s position in the array as you instantiate it.
  2. Which is less favorable, is to iterate over the array until you find the object the player has clicked like so.