How to get the mouse coordinates inside a game object

Hi Guys,

Thanks for taking the time to read/answer this question.

Basically im developing a (2D) Match 3 Game. I have a grid drawn procedurally and that was a success and stored all the blocks into a List.

Whenever I use raycasting to get the position of my mouse 0,0 is not exactly Block[0,0]. So i was wondering what the best way was to get mouse click inside the grid that i have drawn.


There are 2 ways to go about this problem as I see it…
EITHER, A) you want to have individual gameobjects, each with a “clickscript” that says on void down, record which one I click and then the next one I click, and then check if all are matched. I do this in a match 3 balls game ( like the ones my wife plays on the iphone ).

If you are simply doing this on a flat plane for instance, then I did mine like this:

And then, all I had to do was setup my imagine coordinate box for each one selected… Then record that selection onto an ARRAY of like Vector2 gridLayout; , where the vector2 x,y is the position on the grid