0
0
Unityframework~20 mins

Waypoint systems in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Waypoint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this waypoint index update code?

Consider a Unity C# script that moves an object through waypoints in a loop. What will be the value of currentWaypointIndex after running the Update method once if currentWaypointIndex starts at 2 and there are 4 waypoints?

Unity
int currentWaypointIndex = 2;
int totalWaypoints = 4;

void Update()
{
    currentWaypointIndex = (currentWaypointIndex + 1) % totalWaypoints;
}
A3
B4
C2
D0
Attempts:
2 left
💡 Hint

Think about how the modulo operator (%) works with the total number of waypoints.

🧠 Conceptual
intermediate
1:00remaining
Which statement best describes the purpose of a waypoint system in Unity?

Choose the best description of what a waypoint system does in a Unity game.

AIt controls the lighting and shadows in the scene.
BIt automatically generates 3D models for the game environment.
CIt defines a set of points that an object can follow to move along a path.
DIt manages user input from the keyboard and mouse.
Attempts:
2 left
💡 Hint

Think about how characters or objects move along predefined paths.

🔧 Debug
advanced
2:00remaining
Why does this Unity waypoint movement code cause the object to stop moving after the first waypoint?

Examine the code below. The object moves to the first waypoint but then stops. What is the cause?

Unity
public Transform[] waypoints;
private int currentWaypoint = 0;
public float speed = 5f;

void Update()
{
    transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypoint].position, speed * Time.deltaTime);
    if (transform.position == waypoints[currentWaypoint].position)
    {
        currentWaypoint++;
    }
}
AThe waypoints array is empty, so the object has nowhere to move.
BComparing Vector3 positions with '==' can fail due to floating point precision, so the condition never becomes true after the first move.
CThe speed variable is too high, causing the object to skip waypoints.
DThe code never resets currentWaypoint, so it goes out of bounds causing an error.
Attempts:
2 left
💡 Hint

Think about how floating point numbers behave when compared for equality.

📝 Syntax
advanced
1:30remaining
Which option correctly declares a list of waypoints in Unity C#?

Choose the correct syntax to declare a public list of waypoints as Transforms in Unity C#.

Apublic List<Transform> waypoints = new List<Transform>();
Bpublic List waypoints = new List<Transform>();
Cpublic List<Transform> waypoints = List<Transform>();
Dpublic List<Transform> waypoints = new List();
Attempts:
2 left
💡 Hint

Remember how to instantiate generic lists in C#.

🚀 Application
expert
2:00remaining
What is the output of this Unity C# code that cycles through waypoints with wrap-around?

Given the code below, what will be the value of currentWaypoint after calling NextWaypoint() three times starting from 0, if there are 3 waypoints?

Unity
int currentWaypoint = 0;
int totalWaypoints = 3;

void NextWaypoint()
{
    currentWaypoint = (currentWaypoint + 1) % totalWaypoints;
}
A2
B3
C1
D0
Attempts:
2 left
💡 Hint

Calculate the index step by step using modulo arithmetic.