0
0
Unityframework~20 mins

Tilemap painting in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tilemap Painting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Tilemap painting code?

Consider this Unity C# script snippet that paints tiles on a Tilemap. What will be the color of the tile at position (1, 1) after running this code?

Unity
using UnityEngine;
using UnityEngine.Tilemaps;

public class PaintTiles : MonoBehaviour {
    public Tilemap tilemap;
    public TileBase tile;

    void Start() {
        Vector3Int pos = new Vector3Int(1, 1, 0);
        tilemap.SetTile(pos, tile);
        tilemap.SetColor(pos, Color.red);
        tilemap.SetColor(new Vector3Int(0, 0, 0), Color.blue);
    }
}
AThe tile at (1,1) is transparent (no color).
BThe tile at (1,1) is red.
CThe tile at (1,1) has the default color (white).
DThe tile at (1,1) is blue.
Attempts:
2 left
💡 Hint

Remember that SetColor changes the color of the tile at the specified position.

🧠 Conceptual
intermediate
1:30remaining
Which method paints a tile on a Tilemap in Unity?

In Unity's Tilemap system, which method is used to place a tile at a specific grid position?

Atilemap.SetTile(Vector3Int position, TileBase tile)
Btilemap.PlaceTile(Vector3Int position, TileBase tile)
Ctilemap.AddTile(Vector3Int position, TileBase tile)
Dtilemap.PaintTile(Vector3Int position, TileBase tile)
Attempts:
2 left
💡 Hint

Look for the official Unity Tilemap API method that sets a tile.

🔧 Debug
advanced
2:30remaining
Why does this Tilemap painting code not show the tile?

Look at this code snippet. Why does the tile not appear on the Tilemap after running?

Unity
using UnityEngine;
using UnityEngine.Tilemaps;

public class PaintTiles : MonoBehaviour {
    public Tilemap tilemap;
    public TileBase tile;

    void Start() {
        Vector3 pos = new Vector3(2, 2, 0);
        tilemap.SetTile(Vector3Int.FloorToInt(pos), tile);
    }
}
AVector3Int.FloorToInt(pos) is invalid and causes a runtime error.
BUsing Vector3 instead of Vector3Int causes the tile not to appear.
CThe tile variable is not assigned, so no tile is painted.
DTilemap.SetTile requires a Vector3 position, not Vector3Int.
Attempts:
2 left
💡 Hint

Check if the tile variable has a value before painting.

📝 Syntax
advanced
2:00remaining
Which option correctly paints multiple tiles in a loop?

Which code snippet correctly paints tiles at positions (0,0), (1,0), and (2,0) on a Tilemap?

Afor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector3Int(x, 0, 0), tile); }
Bfor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector3(x, 0, 0), tile); }
Cfor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector2Int(x, 0), tile); }
Dfor (int x = 0; x < 3; x++) { tilemap.SetTile(new Vector2(x, 0), tile); }
Attempts:
2 left
💡 Hint

Tilemap.SetTile requires a Vector3Int position.

🚀 Application
expert
3:00remaining
How many tiles are painted after this code runs?

Given this code, how many tiles will be painted on the Tilemap?

Unity
using UnityEngine;
using UnityEngine.Tilemaps;

public class PaintTiles : MonoBehaviour {
    public Tilemap tilemap;
    public TileBase tile;

    void Start() {
        for (int x = 0; x < 3; x++) {
            for (int y = 0; y < 3; y++) {
                if ((x + y) % 2 == 0) {
                    tilemap.SetTile(new Vector3Int(x, y, 0), tile);
                }
            }
        }
    }
}
A9 tiles
B6 tiles
C4 tiles
D5 tiles
Attempts:
2 left
💡 Hint

Count how many (x,y) pairs from 0 to 2 satisfy (x + y) % 2 == 0.