- Home /
I am trying to make a level editor that allows you to place tiles on a tilemap. How do I get it so you can place one of these tiles?
For my 2D game I am adding a level editor. I designed my official levels in my game using tilemaps, and to keep things consistent and make things work I also want everything to be designed using tilemaps. I am trying to make it so that the player can place tiles and destroy tiles on a tilemap. How do I do this?
Answer by lgarczyn · Oct 04, 2019 at 09:00 PM
Not a very precise question, but here's a few steps:
First you want to get the world position of your mouse.
If the game is 2d, you can simply do
if (Input.GetMouseButtonDown(0))
{
Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
TileData tile = tilemap.Tile((int)pos.x, (int)pos.y);
}
Once that is done, you can set a highlight on that position, so the players knows which tile he is pointing. This can be done a lot of ways, like moving a gameobject to the TileData transform.
After that, use the mouse input to create or destroy tiles. This can be done using the TileMap API.
You can also have a menu to select which tile you want to build, which would be simple UI elements with the same texture as the tiles.
Your answer
![](https://koobas.hobune.stream/wayback/20220612212943im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
URGENT!!! Not able to slice in the sprite editor 2 Answers
How to make one-way platforms using a tilemap? 2 Answers
Cant see tilemap collider 1 Answer
How To Change Player As Soon as He Take Powerup 1 Answer
Stop jump animation 1 Answer