In order to use Tiles in an easy way, it is better to use Unity’s Tilemap Grid system. To create a Tilemap, right click in the Hierarchy window and select 2D — Tilemap.
In Unity, Tilemaps function in a way similar to Layers. Just like we can have Foreground, mid and background layers; we can have seperate Tilemap grids. Each grid will be rendered according to their order in Layout in the game.
In order to paint in the Tilemap, we need the Tile Palette (I have basicly explained how to enable it on my previous article). A palette is the host for the sprites that we can use in a particular Tilemap. We can have many number of Palettes according to our needs in the game.
To simply create a new Palette, click on Create new Palette, name it and place it according to your desired organization in the project. Just a reminder, make sure to always check the Active Tilemap is the tilemap that you want to work on.
Before dragging the spritesheet to your Plaette make sure to have them sliced. If you have a sprite that is consisting of seperate tiles, make sure to Slice them into seperate sprites.
Set the “Pixels Per Unit” same as the size with the sliced sprites. Then, simply drag and drop the spritesheet (not the individual sprites) to the Tile Palette and it will convert the each sprite to a Tile to be used in the game.
We can easily switch in between different Palettes by clicking on the drop down list on the left side of the “Edit”.
And we are ready to paint! It is surprisingly easy.
As can be seen on the left side, Tile Palette has many painting options. Here, I have used brush. You can also use box, fill according to your needs. The white area represents the area of the main camera.
It is possible to drag multiple set of sprites as Tiles for a single Palette. By using the mouse wheel, we can zoom in and out, and place the new sprite sheet in a place of our desire in the same Palette.
Unity allows us to focus on the desired Tilemap to make a clear build. Make sure to switch to the right Tilemap while working on.
It is possible to manipulate the colors and alpha values of sprites that we use in the Tiles. Click on the select tool from the Palette, select the sprites that you want to manipulate and manipulate it from the Inspector.
In the screenshot below, I have changed the alpha value of the waterfall by selecting the all of its tiles.
Lastly, the Colliders! Unity has a special collider for the Tilemaps namely “Tilemap Collider2D”. To add a collider, select the Tilemap from the Hierarchy and add the “Tilemap Collider2D” as a component. You will notice that each of the Tile will now have a collider.
However, this results in redundant usage of collider system as it also included colliders on the tiles that has no possibility of collision (the inner sides). To eliminate it, we need to set the “Used By COmposite” property of the Tilemap Collider on. To do that, we need to add the Composite Collider 2D as a component (which will also add the Rigidbody 2D component automatically). Change the “Body Type” to “Static” from the Rigidbody settings, and check the “Used By Composite” box in the Tilemap Collider. You will notice that only the surface areas will now have a collider on.