0
0
Unityframework~10 mins

Animation events 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 declare a method that can be called by an animation event.

Unity
public void [1]() {
    Debug.Log("Animation event triggered");
}
Drag options to blanks, or click blank then click option'
AUpdate
BAwake
CStart
DOnAnimationEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Using private or non-void methods.
Using Unity lifecycle methods like Start or Update which are not called by animation events.
2fill in blank
medium

Complete the code to add an animation event to an AnimationClip in code.

Unity
AnimationEvent animEvent = new AnimationEvent();
animEvent.time = 1.5f;
animEvent.functionName = [1];
clip.AddEvent(animEvent);
Drag options to blanks, or click blank then click option'
A1.5f
BPlaySound
C"PlaySound"
D"1.5f"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the method name without quotes.
Passing a float value instead of a string.
3fill in blank
hard

Fix the error in the method signature to be compatible with animation events that pass a float parameter.

Unity
public void OnEventTriggered([1] value) {
    Debug.Log($"Value: {value}");
}
Drag options to blanks, or click blank then click option'
Astring
Bfloat
Cint
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or string instead of float.
Not matching the parameter type with the animation event.
4fill in blank
hard

Fill both blanks to create an animation event that calls 'TriggerEffect' at 2 seconds.

Unity
AnimationEvent event = new AnimationEvent();
event.[1] = 2.0f;
event.[2] = "TriggerEffect";
clip.AddEvent(event);
Drag options to blanks, or click blank then click option'
Atime
BfunctionName
Cname
Dduration
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'duration' which are not valid properties for animation events.
Mixing up the properties.
5fill in blank
hard

Fill both blanks to define a method that receives a string parameter from an animation event.

Unity
public void [1]([2] message) {
    Debug.Log($"Message: {message}");
    // Additional logic here
}
Drag options to blanks, or click blank then click option'
ADisplayMessage
Bstring
Cint
DShowMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using int instead of string for the parameter.
Using a method name that does not match the animation event.