0
0
Unityframework~10 mins

Animation states and transitions 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 Animator component.

Unity
Animator animator = GetComponent<[1]>();
Drag options to blanks, or click blank then click option'
AAnimator
BAnimation
CAnimatorController
DAnimationClip
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Animation' instead of 'Animator' causes errors because 'Animation' is an older system.
Trying to get 'AnimatorController' which is not a component.
2fill in blank
medium

Complete the code to trigger a transition using a trigger parameter.

Unity
animator.[1]("Jump");
Drag options to blanks, or click blank then click option'
APlay
BSetBool
CSetTrigger
DResetTrigger
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'SetBool' instead of 'SetTrigger' won't trigger the transition.
Using 'Play' plays an animation state directly but doesn't set parameters.
3fill in blank
hard

Fix the error in the code to check if the Animator is currently in the 'Run' state.

Unity
bool isRunning = animator.GetCurrentAnimatorStateInfo(0).[1]("Run");
Drag options to blanks, or click blank then click option'
AIsName
Bname
CstateName
DGetName
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to compare 'name' property directly to a string causes errors.
Using 'GetName' which does not exist.
4fill in blank
hard

Fill both blanks to smoothly transition to the 'Attack' animation state.

Unity
animator.[1]("Attack", 0, [2]);
Drag options to blanks, or click blank then click option'
APlay
BSetTrigger
C0f
D0.5f
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'SetTrigger' with a float parameter causes errors.
Using normalized time 0.5f starts animation halfway through.
5fill in blank
hard

Fill all three blanks to create a dictionary mapping animation states to their durations, filtering only states longer than 1 second.

Unity
var durations = new Dictionary<string, float> { {"Idle", 1.2f}, {"Walk", 0.8f}, {"Run", 1.5f} };
var filtered = durations.Where(kv => kv.Value [1] [2]).ToDictionary(kv => kv.Key, kv => kv.Value [3] 0);
Drag options to blanks, or click blank then click option'
A>
B1
C-
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters shorter durations, not longer.
Subtracting a non-zero value changes durations unexpectedly.