- Home /
What is grid in unity and how can I implement it ?
Hey guys, Em a begineer.. I need to place a grid on my map in unity and would like to access it to place a simple object on mouse click. How can I acheive this ?
I am unable to understand the grid functionality, should I have to write a 2d array code or is there something in unity that I can access, and what is basically the grid like something when I click my background image ?
Answer by BerggreenDK · Sep 28, 2011 at 09:11 PM
Unity makes a "free vector world". So you decide what resolution your grid should be.
Lets say your grid is 1x1 unit, then you could add a Default Plane, rotate it 90 degress and assign a texture with a "grid" onto it. As I recall this object needs to be scaled to match the units in Unity, but play around and see what fits your needs.
Regarding the click on it. There are several options, but none is "free". You'll need to do the scripts for it. Its not standard in that sense.
You can go for a Raycast/collider method or you could use WorldToScene coords and many other tricks. You can basically do everything, as long as you are willing to write the scripts for it.
ok thnx for the reply. As I am going to place towers on my plane so what my understanding up to now is to make 2D Array first on my plane and access it to place towers. right ? for e.g place tower on myArray[0,0] OR I should access plane position without making 2D array ? for eg. place tower on transform.position(x,y,z). The game I am going to make is like http://fieldrunners.com/media/
For a gamle type like Tower Defence a grid could be an option. But if you place the "tower spawn points" as other objects/triggers then that could also do the job alone. Its more up to you how you want to build your algoritms. You also have to think about the "path" for the enemies. Is that vector waypoints or do they have to follow your grid tile for tile.
I am not going to follow any desired path. Enemy will move forward where there is no collision
Your answer
![](https://koobas.hobune.stream/wayback/20220612230226im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
How can I make grid tiles/plane transparent 1 Answer
RTS Grid Initialisation 0 Answers