Tilemaps
A Tilemap is a way to build a static background environment. Tilemaps can have collision as well.
Creating a Tilemap
To create a tilemap, right-click on the SampleScene and select GameObject > 2D Object > Tilemap > Rectangular
.
In the Inspector, you will need to add a “Tilemap Collider 2D” (1.). Then, click on the “Open Tile Palette” button (2.).
Creating a Tile Palette
A Tile Palette is a way to store the tiles that you will use to create your background.
- Select “Create New Palette” and a dropdown will show.
- Name it “Ground Palette”.
- Click “Create”.
A dialog will open prompting you to select what folder you want to put the palette into and for our small project, just hit “Select Folder”. In larger projects, you’ll want to organize Prefabs, Tilemaps, etc. in folders.
Tagging the Tilemap as Ground
Later, we will be checking if our Player is colliding with the ground. To do this, we need to add a Tag (label) to the Tilemap. Select the Tilemap from the Hierarchy and add a “Ground” Tag.
After pressing “Save” above, you will be redirected to the Inspector for the Tilemap. Select “Ground” from the Tag dropdown menu.