0
0
Unityframework~20 mins

Terrain system basics in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terrain Mastery
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 Unity C# code snippet?
Consider the following code that modifies a terrain's height at a specific point. What will be the height value printed in the console?
Unity
using UnityEngine;

public class TerrainTest : MonoBehaviour
{
    void Start()
    {
        Terrain terrain = GetComponent<Terrain>();
        float[,] heights = terrain.terrainData.GetHeights(0, 0, 1, 1);
        heights[0, 0] = 0.5f;
        terrain.terrainData.SetHeights(0, 0, heights);
        float newHeight = terrain.terrainData.GetHeight(0, 0);
        Debug.Log(newHeight);
    }
}
A1.0
B0.0
C0.5
DTerrain height in meters (depends on terrain size)
Attempts:
2 left
💡 Hint
Remember that terrain heights are normalized and scaled by terrain size.
🧠 Conceptual
intermediate
1:00remaining
Which Unity component is required to display a terrain in a scene?
You want to add a terrain to your Unity scene. Which component must be attached to the GameObject to render the terrain?
ATerrain
BMeshRenderer
CSpriteRenderer
DCanvas
Attempts:
2 left
💡 Hint
This component handles terrain rendering and collision.
🔧 Debug
advanced
2:00remaining
Why does this terrain height modification code not change the terrain?
Look at this code snippet that tries to raise the terrain height at (10,10) by 0.1. Why does the terrain not change visually?
Unity
Terrain terrain = GetComponent<Terrain>();
float[,] heights = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution);
heights[10, 10] += 0.1f;
// Missing code here
AThe code does not call SetHeights to apply the modified heights back to the terrain.
BThe terrain component is missing from the GameObject.
CThe height value 0.1f is too small to see any change.
DThe index 10,10 is out of range for the heightmap array.
Attempts:
2 left
💡 Hint
Modifying the array alone does not update the terrain.
📝 Syntax
advanced
2:00remaining
Which code snippet correctly sets a 3x3 flat area of height 0.2 on a terrain?
You want to set a 3x3 area starting at (5,5) to height 0.2. Which code snippet does this correctly?
A
float[,] heights = new float[5,5];
for(int i=5; i&lt;8; i++)
  for(int j=5; j&lt;8; j++)
    heights[i,j] = 0.2f;
terrain.terrainData.SetHeights(5, 5, heights);
B
float[,] heights = new float[3,3];
for(int i=0; i&lt;3; i++)
  for(int j=0; j&lt;3; j++)
    heights[i,j] = 0.2f;
terrain.terrainData.SetHeights(0, 0, heights);
C
float[,] heights = new float[3,3];
for(int i=0; i&lt;3; i++)
  for(int j=0; j&lt;3; j++)
    heights[i,j] = 0.2f;
terrain.terrainData.SetHeights(5, 5, heights);
D
float[,] heights = new float[3,3];
for(int i=5; i&lt;8; i++)
  for(int j=5; j&lt;8; j++)
    heights[i,j] = 0.2f;
terrain.terrainData.SetHeights(5, 5, heights);
Attempts:
2 left
💡 Hint
The heights array size must match the area size, and indices inside the array start at 0.
🚀 Application
expert
3:00remaining
How to efficiently raise terrain height in a circular area using Unity's Terrain API?
You want to raise the terrain height smoothly in a circular area with radius 10 around point (x=50, z=50). Which approach is best to achieve this efficiently?
AGet the entire heightmap, loop through all points, calculate distance to center, raise height proportionally, then set the entire heightmap back.
BGet a square heightmap area covering the circle, loop through points, calculate distance to center, raise height proportionally, then set only that area back.
CUse multiple SetHeights calls for each point in the circle to raise height individually.
DModify the terrain's height property directly without using heightmaps.
Attempts:
2 left
💡 Hint
Minimize the area you read and write to improve performance.