Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The method name 'OnAnimationEvent' is a common choice for animation event handlers. It must be public and void with no parameters to be called by animation events.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the method name without quotes.
Passing a float value instead of a string.
✗ Incorrect
The functionName property requires the method name as a string, so it must be in quotes.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or string instead of float.
Not matching the parameter type with the animation event.
✗ Incorrect
Animation events can pass a float parameter, so the method must accept a float argument.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'duration' which are not valid properties for animation events.
Mixing up the properties.
✗ Incorrect
The 'time' property sets when the event triggers, and 'functionName' sets which method to call.
5fill in blank
hardFill 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'
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.
✗ Incorrect
The method name 'DisplayMessage' is a valid choice. The parameter type must be 'string' to receive string data from the animation event.