Hey there,
I’m trying to place and destroy tiles on a layer in unity’s new Tilemap system during runtime based on an event from the player. For example say the player wants to place a torch or a crafting table down, all they would have to is Left click and a tile corresponding to what they have selected in their inventory would be placed down on a tilemap.
In my hierarchy I have a grid with the following layers: Ore, Walls, Floor, and Decoration.
Say for example I wanted to destroy a section of the wall on the Walls tilemap or place down a torch on the Decoration tilemap, how would I go about doing that?
Any code examples would be appreciated. Thank you!
Hey, although it’s much later, I found a solution to this question as i was searching for it myself.
The best way i found to do this was
Tilemap tilemp; void Start() { tilemp = GameObject.Find("Grass").GetComponent<Tilemap>(); } void Update() { Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { Vector3Int selectedTile = tilemp.WorldToCell(point); tilemp.SetTile(selectedTile, null); } }
What this essentially does is it looks for the mouseposition and converts it into a Vector3Int, a vector3 the tilemap can use, And when you click, it sets the tile that your cursor is on to null (nothing)
Good day.
You are asking the more basic issue about TileMaps. So I think you shloud go to watch some yourtube tutorial / Unity manual to find your answers.
If once you spent your time trying to solve it, there is something you dont get, come here again and we will spend our time trying to help. But we are here for pleasure, not for work, so dont make us to waste time if you didnt spent any minute trying to solve it…
This is not a Code provider service…
Bye.