Optional: Dead Animation
Last updated
Last updated
IMPORTANT: Note that this is not required for any projects in this course
Since we don't want the hero_dead animation clip to loop continuously, we need to set that configuration as part of the hero-dead animation clip asset. In the project assets panel, find and select the hero-dead animation clip. Once the animation-clip is selected, in the inspector panel, uncheck the Loop Time checkbox. Loop-time will remain checked for all other animation clips.
Select hero_dead Animation Clip in Project Assets
Uncheck Loop Time in Inspector Panel for hero-dead Animation clip
Finally, you may choose to add an animation-event to the hero_dead Animation clip. An animation event allows for a function/method to be executed when at a specific animation keyframe is played. In this case, we'd like the hero_dead animation to play completely before leaving the scene or reloading the scene. So, an animation event allows for some specially defined event to be triggered when a specific keyframe is executed. The animation event can be configured to execute any public method with the following syntax: public void someMethod( )
, but this method must be defined within a script-component that's on the same gameObject as the animation clip that has the animation event defined.
Select the player in the hierarchy.
Open the Animation panel
From the Animation panel dropdown, select the hero_dead animation clip
Select the timeline section above the final keyframe
Push the button: with icon: small white vertical rectangle, when you hover over this icon, it will say Animation Event
In the inspector, select the Function from the dropdown, to be executed as the Animation Event.(See images below)
If the ReloadScene( ) method hasn't been added to the player controller yet, see code below, it will need to be customized for your game details.
You may want to add additonal keyframes, at a later keyframe time slice, if you want the dead animation to be displayed for a longer time before the scene is reloaded.
As seen in the image below, once you've configured an animation-event, then when you hovering over the icon, it will display the message shown below, which is the name of the function / method you've configured to be executed.