I have a tower of defense style game where I have to place cards on to the flat terrain.
The cards (GUI) at the bottom left are to be dragged and dropped on to the terrain.
How can I go about it?
I have a tower of defense style game where I have to place cards on to the flat terrain.
The cards (GUI) at the bottom left are to be dragged and dropped on to the terrain.
How can I go about it?
Insert an empty GameObject into your scene and add a thin box collider that covers your entire grid. Then, when a card is dropped, simply raycast against it and calculate grid coordinates based on the hit point.
Thanks KaelisAsur!!!
The issue is that the card has to drop into predefined grids as when I drag the card the grid over which the card is hovering should highlight
How do I draw a invisible grid?
How do I do the above in this case?
Thanks for help
Say your grid is in the xz plane, y = 0. Then if you are moving the card in a plane parallel to the xz plane, say at y = 5. By the position of the card (x and z coords) you know in which grid you are (just check if the the xz position of your card is contained in a rectagle). If you have a lot of rectangles in the grid, you should try to think of a way to speed up this check. For example if your rectangles’ center x coords are 0, 1, 2, 3, etc, then just take the x coord of the card and round and you know in which column (or row) in the grid you are, etc, etc.
To highlight a rectanagle you can position a quad with a transparent texture on top of the rectagle if the terain is even. You can also use line renderer.
If the terrain is uneven, use projector.
Thanks again!!!
Again, I am just not able to figure out how
Any help would be appreciated. Also, Somebody knows of any reference/ code please lemme knw.