Langsung ke konten
Skillpedia
Pemrograman umum6.6k Β· #13851

unity-tilemap-2d

Fungsinya

Skill ini menjelaskan cara membangun dan membuat skrip peta tile 2D di Unity 6. Skill ini untuk pengembang yang membuat level 2D dari gambar tile.

Kapan dipakai

  • βœ“Saat Anda ingin melukis level 2D dengan Tile Palette di Unity.
  • βœ“Ketika tile perlu collision, atau tepi yang tersambung otomatis dengan Rule Tile.
  • βœ“Ketika Anda memerlukan skrip untuk membuat atau mengubah tile saat game berjalan.

Link skill

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-tilemap-2d/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-tilemap-2d/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBantu saya melukis level platform 2D di Unity dan buat dinding solid untuk pemain.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini menjelaskan cara menyiapkan grid dan tilemap, menambahkan collision pada peta, memakai rule tile untuk tepi otomatis, dan mengubah tile lewat kode.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Unity 2D Tilemap

Author and script tile-based 2D levels in Unity 6.3 LTS with the Grid/Tilemap system, the Tile Palette, colliders, and runtime painting. Targets Unity 6.3 LTS (6000.3).

Package note: the core Tilemap (Grid, Tilemap, Tile, TilemapCollider2D) is built in, and so is the Tile Palette with its default brush. Rule Tiles, Animated Tiles, and the extra brushes (Random, Line, GameObject, Group) live in the separate "2D Tilemap Extras" package (com.unity.2d.tilemap.extras, 6.0.x for Unity 6.3) β€” install it via Package Manager before using RuleTile.

When to use

  • Use when laying out a 2D level by painting tiles, setting up a Grid + Tilemap, adding collision to the map, using auto-tiling Rule Tiles, or generating/editing tiles from script.
  • Use when scenes contain a Grid with Tilemap children, or *.asset tile/palette files.

When not to use: level design practice (pacing, blockout, layout principles) β†’ level-design. 3D tile/grid placement β†’ Unity's own 3D tooling (ProBuilder / grid brushes; no dedicated skill here). The platformer character that moves over the tiles β†’ platformer / unity-physics.

Core workflow

  1. Create the grid: GameObject β†’ 2D Object β†’ Tilemap β†’ Rectangular (the Grid's Cell Layout also offers Hexagonal and Isometric for hex/iso levels). This makes a Grid with a child Tilemap (+ TilemapRenderer). Use one Tilemap per layer (background, ground, foreground) and set each renderer's sorting.
  2. Open the Tile Palette (Window β†’ 2D β†’ Tile Palette), drag in a sliced sprite sheet to create Tile assets, then paint with the brush tools.
  3. Add collision to the solid layer: TilemapCollider2D. For one merged collider (far cheaper and gap-free), also add CompositeCollider2D (+ a Rigidbody2D set to Static) and set the tilemap collider's Composite Operation to Merge.
  4. Auto-tile with Rule Tiles (2D Tilemap Extras) so edges/corners pick the right sprite automatically instead of hand-placing every variant.
  5. Edit at runtime via script with cell coordinates (Vector3Int): SetTile, GetTile, SetTilesBlock, converting world↔cell with the Grid/Tilemap.
  6. Verify in Play mode: confirm collisions (Physics Debugger), sorting order, and that RefreshAllTiles ran after bulk edits.

Patterns

1. Painting tiles at runtime (cell coordinates)

using UnityEngine;
using UnityEngine.Tilemaps;

public class TilePainter : MonoBehaviour
{
    [SerializeField] private Tilemap tilemap;   // assign the target Tilemap
    [SerializeField] private TileBase groundTile;

    // World position -> cell, then place a tile.
    public void PaintAt(Vector3 worldPos)
    {
        Vector3Int cell = tilemap.WorldToCell(worldPos);
        tilemap.SetTile(cell, groundTile);
    }

    public bool IsSolid(Vector3 worldPos)
        => tilemap.GetTile(tilemap.WorldToCell(worldPos)) != null;
}

2. Bulk fill a region (faster than per-cell SetTile)

// SetTilesBlock writes a whole BoundsInt in one call β€” use it for procedural rooms/floors.
public void FillFloor(Tilemap map, TileBase tile, int width, int height)
{
    var bounds = new BoundsInt(0, 0, 0, width, height, 1);
    var tiles  = new TileBase[width * height];
    for (int i = 0; i < tiles.Length; i++) tiles[i] = tile;
    map.SetTilesBlock(bounds, tiles);
}

3. Clearing and refreshing

tilemap.SetTile(cell, null);   // null erases the tile at that cell
tilemap.RefreshTile(cell);     // re-evaluate just this cell's rule/animated neighbors (cheap)
// RefreshAllTiles() re-evaluates the ENTIRE map β€” reserve it for full regenerations, not per-edit.

Pitfalls

  • RuleTile type not found β€” it's not built in. Install the 2D Tilemap Extras package (com.unity.2d.tilemap.extras) via Package Manager.
  • A collider per tile tanks performance / leaves seams β€” add a CompositeCollider2D with a static Rigidbody2D and set Composite Operation to Merge to merge the whole layer into one smooth shape.
  • No "Used By Composite" checkbox, or an obsolete warning on usedByComposite β€” Unity 6 replaced it with Composite Operation (Collider2D.compositeOperation). Old usedByComposite = true maps to CompositeOperation.Merge; write that instead.
  • Small gaps remain between merged tiles β€” raise the Tilemap Collider 2D's Extrusion Factor so
Pertanyaan umum

Apakah saya perlu paket tambahan untuk Rule Tile?

Ya. Rule Tile berasal dari paket 2D Tilemap Extras yang harus dipasang lebih dulu.

Apakah skill ini merancang tata letak level?

Tidak. Prinsip desain level dibahas dalam skill desain level terpisah.

Apakah ini mencakup grid 3D?

Tidak. Penempatan tile 3D berada di luar cakupan skill ini.

Detail

Deskripsi asli dari pembuat

Build and script 2D tilemaps in Unity 6.3 LTS: the Grid + Tilemap components, the Tile Palette, tilemap colliders, rule tiles, and runtime SetTile/GetTile painting. Use when painting tile levels, adding a TilemapCollider2D, using rule or animated tiles, generating tilemaps from code, or when the user mentions Unity tilemap, tile palette, rule tile, or Grid.

repo: gamedev-skills/awesome-gamedev-agent-skills

Popularitas

Bintang GitHub
6.6k
Peringkat
#13851
Lisensi
Apache-2.0
Diperbarui
28/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa