match 3 puzzle game

how to create match 3 puzlle game? I fill array with random numbers from 1 to 4 and in FOR cycle I check if number is 1 I instantiate object, if number is 2 I instantiate another object and so on. But I don't know how to understand on which place is clicked object in array to do adequate actions. Can you give code example ?

there are different ways to do this. first of all if the position of all objects is fixed you can do something like this. for example think you have 10x10 objects. each object is a box/sphere collider of width 1. the first object is placed at 0,0,0 and the last at 10,10,0. in OnMouseDown event of each object check it's position and use the numbers in array elements.

function OnMouseDown ()
{
   myArray[transform.position.x,transform.position.y,0] = 3;
}

myArray is an int array. in js you can not create them but you can use them. the second approach is to create objects at runtime or use Start function to get x,y position and use them for values of array elements. the other ways are like what i showd you so there is no need to write code. i provide cs code for you too.

void Start ()
{
myX = transform.position.x;
myY = transform.position.y;
}

then use myX and myY in click events and raycasts and ... if the positions are not fixed you can use the inspector to set values.