Need a little help in script

I need a little help.
In my app is a 8x8 or bigger grid ( simple planes ).
Lets say i want to planes change color/size/do other action when i click them.
I want to activate not only 1 plane, nor 5.
The center, + right,left,up,down plane.
This is the 2-3th hour and i still can’t imagine how to do this.
Thank you!

10088-d.png

There are few diffrent ways you can do this. If you could tell a bit more about how are you placing the planes (is the grid generated at run-time or not), Then I can chose what way should fit best.

–

[This][1] or [that][2] might help you. If it doesn't try to google for multidimensional array or jagged array. [1]: http://answers.unity3d.com/questions/276919/writing-jagged-arrays.html [2]: http://answers.unity3d.com/questions/54695/how-to-declare-and-initialize-multidimensional-arr.html

–

1 Answer

1

make an array to symbolize each block
(this is c#)

//[0,0][0,1][0,2][0,3][0,4]
//[1,0][1,1][1,2][1,3][1,4]
//[2,0][2,1][2,2][2,3][2,4]

public int[,] BlockArray = new int[3,5];

if klick BlockArray[x,y]
   saveX=x //i don't know how to do this step, but i bet its not that hard
   saveY=y //i don't know how to do this step, but i bet its not that hard

   BlockArray[saveX,saveY]//[1,1] if klicked [1,1]
   does_stuff
   BlockArray[saveX,saveY-1]//[1,0] if klicked [1,1]
   does_stuff
   BlockArray[saveX,saveY+1]//[1,2] if klicked [1,1]
   does_stuff
   BlockArray[saveX-1,saveY]//[0,1] if klicked [1,1]
   does_stuff
   BlockArray[saveX+1,saveY]//[2,1] if klicked [1,1]
   does_stuff

should work huh? :slight_smile: maybe not the prettiest

*PS this is not “CODE” per say, its just the concept on how it could be done…

*PPS my first Answerer, i’m not that pro but i might help someone!