Tilemap is a component in Unity that you can use to build 2D levels. It consists of multiple different components that together create a system you can use to paint yourself 2D levels. This allows fast prototyping and level creation.
If your project doesn't contain the Tilemap editor already, you need to install it. To check if your project contains the package, open the Package Manager via the Window menu. If the list doesn't contain 2D Tilemap Editor, you can follow the guide below to learn how to add it.
Using this guide you can install the 2D Tilemap Editor. You can install other types of packages as well following this method.
First, you need to open the Package Manager. You can find it by opening the Window dropdown menu and selecting the Package Manager.
In this view, you can check if your Unity project has the 2D Tilemap Editor installed. If it doesn't appear in the list, it's not included in your project yet. From the top-left, click Packages and then In Project and select Packages followed by Unity Registry.
From this list, you'll find the 2D Tilemap Editor. Select it from the list and click the Install button from the bottom-right. The package will be downloaded and installed.
The 2D Tilemap Editor is now installed and should be visible in the package list of Packages: In Project.
Let's import a tileset for your Unity project. You can use the tileset used in this lesson or download a tileset from a website like Open Game Art. If you choose to download another tileset, check the size of a tile if the creator has provided it. Importing a tileset or any other asset is as simple as dragging and dropping the asset to Unity's Project window.
After you have imported the tileset, you can slice it up. Follow the following steps to slice your tileset.
The first step is to check all the import settings. Select your tileset from the Project window.
After selecting the tileset, you should see your Inspector window change. In the Inspector window, set the Texture Type as Sprite, Sprite Mode as Multiple, and Pixels Per Unit as the size of a single tile in your tileset (for our tileset, it's 64). Next, apply the changes and click the Sprite Editor button.
This is the Sprite Editor window. Here you can slice your tileset and edit each tile if needed. To slice the tileset, select the Slice button from the upper-left corner. Set the Type as Grid by Cell Size, set Pixel Size as 64 x 64, Pivot can stay as Center and Method as Delete Existing. Next, click the Slice button.
You can now select a tile and change its properties in the Sprite box. You can edit the name, size, border size, pivot position, and pivot unit mode. You can change the tile size by dragging blue dots in the corners of a tile after selecting one. When you are happy with your sliced tileset, apply the changes by clicking the Apply button on the upper-right corner and close the Sprite Editor window.
You can check your sliced tileset in your assets by clicking the arrow icon on the left side of the asset. This opens the tileset and allows you to see each tile.
Next, let's create a Tile Palette. After that, you can get to creating your level with Tilemap. You'll use the Tile Palette to pick wanted tile or tiles and painting them to the Tilemap.
To create a Tile Palette, you'll use the sliced tileset. The Tile Palette can be used later to paint levels.
To open a Tile Palette window, open the Window menu, hover over the 2D menu, and click Tile Palette.
Your Tile Palette window should be empty at the start. To create a new palette, click Create New Palette button. This will open a box where you can name your palette, set the type of the grid your Tilemap will use, and other options. Give your Tile Palette a name and click Create button. You can save the Tile Palette in your Assets folder.
Next, drag the sliced tileset into the Tile Palette window. After you've dropped the tileset in, you need to select a folder where to save the tiles. You can save them to the Assets folder as well or create a new folder for the tiles.
Now, you have a new Tile Palette ready to use.
Tools in the Tile Palette window are as follows from left to right:
Tähän tulee collapse otsikolla:
With the Tile Palette ready, you can start creating a Tilemap and a 2D level.
One way of creating a Tilemap is to right-click the Hierarchy window, hovering over 2D Object, then Tilemap, and lastly Rectangular. There are other types of Tilemaps as well, but you'll use Rectangular because you'll be creating a 2D level.
To edit a Tilemap, select it from the Hierarchy window. If your Tile Palette window is closed, you can open it via the Window dropdown menu or by pressing the Open Tile Palette button in the lower-right corner of the Scene view.
The next step is to start painting the level. You can select single tile or multiple tiles from the Tile Palette by clicking or dragging over multiple tiles. After selecting a tile or tiles, move to Scene window and start placing the tiles. Remember to save your Scene to not lose you changes.
And here is an example of a finished level.