0
0
Unityframework~10 mins

NavMesh Agent component 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 get the NavMeshAgent component from the GameObject.

Unity
NavMeshAgent agent = gameObject.GetComponent<[1]>();
Drag options to blanks, or click blank then click option'
ANavMeshAgent
BRigidbody
CCollider
DAnimator
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong component type like Rigidbody or Collider.
Forgetting the generic type syntax with angle brackets.
2fill in blank
medium

Complete the code to set the destination of the NavMeshAgent to a Vector3 position.

Unity
agent.[1](targetPosition);
Drag options to blanks, or click blank then click option'
AGoTo
BMove
CSetDestination
DNavigate
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like Move or GoTo.
Trying to assign destination directly instead of using a method.
3fill in blank
hard

Fix the error in the code to check if the NavMeshAgent has reached its destination.

Unity
if (agent.remainingDistance [1] agent.stoppingDistance && !agent.pathPending) {
    // Reached destination
}
Drag options to blanks, or click blank then click option'
A>=
B<=
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than comparison which is incorrect.
Checking equality which may fail due to floating point precision.
4fill in blank
hard

Fill both blanks to create a dictionary of agent speeds for agents with speed greater than 3.

Unity
var fastAgents = agents.ToDictionary(agent => agent.[1], agent => agent.[2]).Where(kv => kv.Value > 3);
Drag options to blanks, or click blank then click option'
Aname
Bspeed
Cdestination
DremainingDistance
Attempts:
3 left
💡 Hint
Common Mistakes
Using destination or remainingDistance as dictionary keys or values.
Mixing up key and value properties.
5fill in blank
hard

Fill all three blanks to filter agents moving faster than 5 and create a dictionary with agent names in uppercase as keys.

Unity
var fastAgents = agents.Where(agent => agent.[1] [2] 5).ToDictionary(agent => agent.[3]);
Drag options to blanks, or click blank then click option'
Aspeed
B>
Cname.ToUpper()
DremainingDistance
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect comparison operators.
Using remainingDistance instead of speed.
Not converting names to uppercase.