- Home /
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 ?
Answer by Ashkan_gc · Feb 28, 2010 at 10:06 AM
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.
@Ashkan Sa'eedi Can you give some more info regarding this Because i am having the same question and didn't get you properly.... here is the link to my question ----> http://answers.unity3d.com/questions/372010/clone-of-bejeweled.html
Your answer
Follow this Question
Related Questions
Javascript for simple grid puzzle? 1 Answer
How to select different objects with raycast (puzzle game) 1 Answer
How to use sections of a texture? 1 Answer
Any idea on how to make objects be clicked in a certain order? (C#) 1 Answer
How do I pick up an object and place it in a spot that kind of like a missing puzzle piece? 0 Answers