Day 111: Introduction to Tilemap in Unity
Objective: Set up the Tilemap system in Unity.
We will start to add everything we need to, to work with Tilemaps. Tilemaps helps us paint out levels with 2D sprites.
In our Hierarchy, let’s create a 2D Tilemap.
After the grid is created, there is a tilemap set as a child to the grid.
We will need to open our Tile Palette. We will go to Window → 2D → Tile Palette. A window will open up.
This window will allow us to drag sprite sheets in and allow us to paint on the map. To add the sprites we will need to go to our sprite sheet and make sure the Texture type is Sprite(2D and UI), Sprite Mode is Multiple, and the Pixels Per Unit is set to the right size for your sprite sheet. The one I am using is created as 128 x 128.
Next go to Sprite Editor to make sure it is spliced correctly.
If it is not spliced correctly, we can go to the top click slice and change the type to Grid by Cell Size. For the Pixel Size, set to the dimensions that your sprite is set as.
After Sliced, click apply on the top right side of the window.
Next step is to Create a new palette for the sprites to sit on. In the Tile Palette window we will go to the drop down under Active TileMap and select Create New Palette. Save in the asset folder. I have created a Folder named TileMap and inside that another for palettes.
After that Is created, the Palette will be empty. We will drag our sprite sheet from earlier and drop it into the new Palette. We will need to save it as well.
Now we have sprites to paint.
In the row at the top select the paint brush and a tile. What ever tile is selected and be painted on the tilemap.
If you want to make a background and midground and more, under grid create more tilemaps. When painting you want to make sure the active tilemap on the Tile Palette has the correct one selected.
Each Tilemap has a Tile Renderer. The renderer will allow the layers to be painted above or below another layer. To do this, you will need to set each renderer layer at a different layer. We set background to 0 and moved up as we got closer.
Last thing we will do is apply a collider on the ground Tile Map so we can walk on it. Select the ground layer and add a TileMap Collider 2D. This will add a collider to each tile painted on the tile map.
This will add a collider to each tile painted on the tile map. To fix this we will need to add a Composite Collider 2D. This will automatically add a Rigidbody 2D.
The last thing to do is on the TileMap Collider 2D. Select Use by Composite. This will only do the outer side of the painted tilemap.
This is all for the Tile Maps.
Thanks for reading and have a wonderful day!!