0
0
Unityframework~10 mins

UI animations 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 start the UI animation.

Unity
Animator animator = GetComponent<Animator>();
animator.[1]("Play");
Drag options to blanks, or click blank then click option'
APlay
BStart
CRun
DBegin
Attempts:
3 left
💡 Hint
Common Mistakes
Using Start or Run instead of Play causes errors because those methods don't exist on Animator.
2fill in blank
medium

Complete 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'
Atransparency
Balpha
Cvisibility
Dopacity
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'opacity' or 'visibility' which are not properties of CanvasGroup.
3fill in blank
hard

Fix 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'
ASetBool
BSetTrigger
CSetFloat
DSetInteger
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.
4fill in blank
hard

Fill 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'
A>
B<
C0.1f
D1.0f
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.
5fill in blank
hard

Fill 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'
A"PopupVisible"
Btrue
Cfalse
D"ButtonActive"
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.