0
0
Unityframework~10 mins

Animator controller for 2D 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 from the GameObject.

Unity
Animator animator = gameObject.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.
Trying to get AnimatorController directly is incorrect.
2fill in blank
medium

Complete the code to set the Animator parameter 'isRunning' to true.

Unity
animator.SetBool("isRunning", [1]);
Drag options to blanks, or click blank then click option'
ATrue
B"true"
C1
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using string "true" instead of boolean true.
Using integer 1 instead of boolean true.
3fill in blank
hard

Fix the error in the code to trigger the 'Jump' animation using a trigger parameter.

Unity
animator.[1]("Jump");
Drag options to blanks, or click blank then click option'
ASetBool
BSetTrigger
CSetFloat
DPlay
Attempts:
3 left
💡 Hint
Common Mistakes
Using SetBool or SetFloat for triggers causes no animation change.
Using Play requires animation state name, not parameter.
4fill in blank
hard

Fill both blanks to create a dictionary that maps animation states to their speed multipliers.

Unity
var animationSpeeds = new Dictionary<string, float> { {"Idle", [1], {"Run", [2] };
Drag options to blanks, or click blank then click option'
A1.0f
B2.5f
C0.5f
D3.0f
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer values without 'f' suffix causes errors.
Mixing up speeds for Idle and Run.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary using LINQ that stores animation names and their lengths if length is greater than 1 second.

Unity
var longAnimations = animations.Where(anim => anim.length [3] 1.0f).ToDictionary(anim => [1], anim => [2]);
Drag options to blanks, or click blank then click option'
Aanim.name
Banim.length
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Swapping name and length in the dictionary.