Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start the UI animation.
Unity
Animator animator = GetComponent<Animator>(); animator.[1]("Play");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Start or Run instead of Play causes errors because those methods don't exist on Animator.
✗ Incorrect
The Animator component uses the Play method to start an animation by name.
2fill in blank
mediumComplete the code to smoothly change the UI element's transparency.
Unity
CanvasGroup canvasGroup = GetComponent<CanvasGroup>(); canvasGroup.[1] = 0.5f;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'opacity' or 'visibility' which are not properties of CanvasGroup.
✗ Incorrect
The CanvasGroup component uses the 'alpha' property to control transparency from 0 (invisible) to 1 (fully visible).
3fill in blank
hardFix the error in the code to trigger a UI animation parameter.
Unity
Animator animator = GetComponent<Animator>(); animator.[1]("IsOpen", true);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using SetTrigger causes errors because it expects no boolean value.
Using SetFloat or SetInteger is wrong for boolean parameters.
✗ Incorrect
To set a boolean parameter in Animator, use SetBool with the parameter name and a boolean value.
4fill in blank
hardFill both blanks to create a fade-out animation coroutine.
Unity
IEnumerator FadeOut(CanvasGroup canvasGroup) {
while (canvasGroup.alpha [1] 0) {
canvasGroup.alpha -= [2];
yield return null;
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes the loop to never run.
Decreasing alpha by 1.0f makes the fade too abrupt.
✗ Incorrect
The loop runs while alpha is greater than 0, decreasing alpha by 0.1f each frame to fade out.
5fill in blank
hardFill all three blanks to create a dictionary of UI elements with their animation states.
Unity
var uiAnimations = new Dictionary<string, bool> {
{ [1], [2] },
{ "MenuOpen", [3] }
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-string keys or non-boolean values causes errors.
Mixing up true and false values changes animation states incorrectly.
✗ Incorrect
The dictionary keys are strings naming UI states, and values are booleans indicating if the animation is active.