Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using SpriteRenderer instead of Tilemap.
Trying to add Rigidbody2D which is for physics.
✗ Incorrect
To work with tilemaps, you add the Tilemap component to your GameObject.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing null which clears the tile.
Passing a position instead of a tile.
✗ Incorrect
You need to pass a TileBase object like myTile to set a tile.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The GetTile method requires a Vector3Int for the position.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetTilesBlock which returns an array, not positions.
Using GetPositions which does not exist.
✗ Incorrect
cellBounds gives all positions in the tilemap bounds, and GetTile gets the tile at each position.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using null instead of a tile to set.
Using wrong loop limits.
✗ Incorrect
The loops run from 0 to 2 (3 times) for x and y, and myTile is set at each position.