0
0
Unityframework~10 mins

Tilemap basics in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new Tilemap component in Unity.

Unity
Tilemap tilemap = gameObject.AddComponent<[1]>();
Drag options to blanks, or click blank then click option'
ACollider2D
BSpriteRenderer
CTilemap
DRigidbody2D
Attempts:
3 left
💡 Hint
Common Mistakes
Using SpriteRenderer instead of Tilemap.
Trying to add Rigidbody2D which is for physics.
2fill in blank
medium

Complete the code to set a tile at position (0, 0) in the Tilemap.

Unity
tilemap.SetTile(new Vector3Int(0, 0, 0), [1]);
Drag options to blanks, or click blank then click option'
AVector3Int.zero
Bnull
Cnew Tile()
DmyTile
Attempts:
3 left
💡 Hint
Common Mistakes
Passing null which clears the tile.
Passing a position instead of a tile.
3fill in blank
hard

Fix the error in the code to get the tile at position (1, 2).

Unity
TileBase tile = tilemap.GetTile(new [1](1, 2, 0));
Drag options to blanks, or click blank then click option'
AVector2Int
BVector3Int
CVector2
DVector3
Attempts:
3 left
💡 Hint
Common Mistakes
Using Vector3 which uses floats and causes errors.
Using Vector2 or Vector2Int which are 2D and not accepted here.
4fill in blank
hard

Fill both blanks to create a dictionary of tile positions and tiles for all tiles in the Tilemap.

Unity
Dictionary<Vector3Int, TileBase> tiles = new Dictionary<Vector3Int, TileBase>();
foreach (var pos in tilemap.[1].allPositionsWithin) {
    tiles[pos] = tilemap.[2](pos);
}
Drag options to blanks, or click blank then click option'
AcellBounds
BGetTile
CGetTilesBlock
DGetPositions
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetTilesBlock which returns an array, not positions.
Using GetPositions which does not exist.
5fill in blank
hard

Fill all three blanks to create a tilemap that sets all tiles in a 3x3 area to a given tile.

Unity
for (int x = 0; x < [1]; x++) {
    for (int y = 0; y < [2]; y++) {
        tilemap.SetTile(new Vector3Int(x, y, 0), [3]);
    }
}
Drag options to blanks, or click blank then click option'
A3
CmyTile
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using null instead of a tile to set.
Using wrong loop limits.