Tilemap painting lets you quickly create game levels by placing tiles on a grid. It saves time and keeps your game world organized.
0
0
Tilemap painting in Unity
Introduction
When building 2D game levels with repeating patterns like floors or walls.
When you want to easily edit or update parts of your game map.
When you need a simple way to design large game areas without drawing each piece manually.
When you want to use Unity's built-in tools to speed up level design.
Syntax
Unity
using UnityEngine;
using UnityEngine.Tilemaps;
public class TilemapPainter : MonoBehaviour
{
public Tilemap tilemap;
public TileBase tile;
void PaintTile(Vector3Int position)
{
tilemap.SetTile(position, tile);
}
}Tilemap is the grid where tiles are placed.
TileBase is the tile you want to paint on the grid.
Examples
Puts the tile at grid position (0,0).
Unity
tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
Puts the tile at grid position (5,3).
Unity
tilemap.SetTile(new Vector3Int(5, 3, 0), tile);
Removes any tile at position (-2,1) by setting it to null.
Unity
tilemap.SetTile(new Vector3Int(-2, 1, 0), null);
Sample Program
This script paints a 3 by 3 square of tiles on the tilemap when the game starts. It loops through positions (0,0) to (2,2) and places the tile at each spot.
Unity
using UnityEngine; using UnityEngine.Tilemaps; public class SimpleTilemapPainter : MonoBehaviour { public Tilemap tilemap; public TileBase tile; void Start() { // Paint a 3x3 square of tiles starting at (0,0) for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { Vector3Int pos = new Vector3Int(x, y, 0); tilemap.SetTile(pos, tile); } } } }
OutputSuccess
Important Notes
Make sure your Tilemap and TileBase references are set in the Unity Editor before running.
Tile positions use Vector3Int where x and y are grid coordinates, and z is usually 0.
You can remove tiles by setting them to null with SetTile.
Summary
Tilemap painting helps build 2D game worlds quickly by placing tiles on a grid.
Use SetTile with grid positions to add or remove tiles.
Looping over positions lets you paint shapes or patterns easily.