0
0
Unityframework~10 mins

Why AI makes games challenging in Unity - Test Your Understanding

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

Complete the code to make the AI move towards the player.

Unity
Vector3 direction = player.position - [1].position;
Drag options to blanks, or click blank then click option'
Atransform
Bplayer
Ctarget
Denemy
Attempts:
3 left
💡 Hint
Common Mistakes
Using player.position twice instead of AI's position.
Using an undefined variable instead of transform.
2fill in blank
medium

Complete the code to make the AI rotate smoothly towards the player.

Unity
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), [1] * Time.deltaTime);
Drag options to blanks, or click blank then click option'
Adistance
Bangle
Cspeed
Dhealth
Attempts:
3 left
💡 Hint
Common Mistakes
Using distance instead of speed for rotation.
Forgetting to multiply by Time.deltaTime.
3fill in blank
hard

Fix the error in the code that makes the AI chase the player only if within range.

Unity
if (Vector3.Distance(transform.position, player.position) [1] chaseRange) {
    ChasePlayer();
}
Drag options to blanks, or click blank then click option'
A<=
B!=
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of <= causes chasing when too far.
Using == is too strict and rarely true.
4fill in blank
hard

Fill both blanks to create a dictionary of enemy names and their health if health is above 0.

Unity
var aliveEnemies = new Dictionary<string, int> { { [1], [2] } };
Drag options to blanks, or click blank then click option'
A"Goblin"
B100
C"Orc"
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as health includes dead enemies.
Using non-string keys causes errors.
5fill in blank
hard

Fill all three blanks to filter enemies with health above 50 and create a dictionary with their names and health.

Unity
var strongEnemies = enemies.Where(e => e.Value [1] [2]).ToDictionary(e => e.Key, e => e.Value [3] 10);
Drag options to blanks, or click blank then click option'
A>
B50
C+
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > filters wrong enemies.
Forgetting to add 10 to health.