- Home /
How to designate an Area as a variable ?
Hello, I'm trying to create a 2d gameplay grid in my game. I've figured out that I should probably use a 2d array to be able to refer to each tile, but I'm not sure how to specify what/where each tile is.
For example, say the game grid consisted of 100 tiles in a 10x10 formation. A1 would be the area from (0,0) to (1,1). A2 would be (1,0) to (2,0), etc. How do I tell Unity... that a certain area of space.. is A1?
Sorry if this is a stupid question but i've been struggling with it for a while.
Answer by Joyrider · Aug 18, 2013 at 01:10 AM
Just create an array to hold your tiles.
And have the array indexes [i][j] of each tile as an indication of the position.
And have (i,j) to (i+1,j+1) as area and thus be positioned at Vector3(i+0.5,j+0.5,0) if the pivot point was in the middle.
A1 would be stored in [0][0] and positioned at (0+0.5,0+0.5) displaying the tile between (0,0) and (1,1)
A2 would be stored in [0][1] and positioned at (0+0.5,1+0.5) displaying the tile between (0,1) and (1,2)
Your answer
![](https://koobas.hobune.stream/wayback/20220613112425im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
global variables possible in unityiphone 1.5.1 1 Answer
acces variables from other script 2 Answers
How do I compare boolean variables? 1 Answer
How do I change a variable in one script from a second script? 1 Answer
Changing variable on diffirent gameobject than that the running script is attached to. 1 Answer