# Optional: Dead Animation

## Optional: hero\_dead animation clip (Advanced)

**IMPORTANT:  Note that this is not required for any projects in this course**&#x20;

### Configure loop-time

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** ![](/files/-M0-KiKQl4YK9uOkMXer)

**Uncheck Loop Time in Inspector Panel for hero-dead Animation clip** ![](/files/-M0-KiKSmhPoR4UlPpCg)

### Add Animation Event to 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.

### Steps to Create An Animation Event

* Select the player in the hierarchy.
* Open the Animation panel&#x20;
* 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  ![](/files/-M0-KiKUsX-JOuBHdS0N)
* 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.

![](/files/-M0-KiKWIZU2g1uhW_qF)

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.

![](/files/-M0-KiKYIUF2tcQH5csV)

```java
///Example Method in PlayerController.cs
///This method is executed from within the hero_dead animation, 
//when the keyframe is played with the corresponding animation event.

    public void ReloadScene(){
        if(GameData.instanceRef.Lives <= 0){
            //go to end scene if there are no more Lives left
            SceneManager.LoadScene("Scene5");  //actual scene name
            StateManager.instanceRef.SwitchState(new Scene5State());  //create new state, pass to StateManager

        }
        else //if there are still Lives left, reload the current scene 
        {
            //reload this current scene
            SceneManager.LoadScene("Scene4");  //actual scene name
            StateManager.instanceRef.SwitchState(new Scene4State());  //create new state, pass to StateManager
            //How should we reset score, health variables for the game?
        }

    }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kdoore.gitbook.io/cs2335/f20_bkup_v2/animation/animation-steps/dead-animation-advanced.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
