Death State

How to create a death state — let’s first set up your death animation and connect it to the any state since we can die on any state. Set a parameter to a bool called death.

Now let’s create a pool on our first person controller that can enable the death bool.


Normally, we’d create a script specific to our player stats or maybe even a player stat manager class, but we will for simplicity add this to our custom controls. Create the died function.

Next, let’s create a script that does unity events. First, let’s create the unity event by adding the events library, creating a private event call _instantDeath, and invoking it when ontriggerenter occurs.

Next, let’s grab the player, drag the gameobject in, and choose died as the function to run. Also be sure to set the cube to trigger. In any state, be sure to set it to death trigger.

Looks good, but we are still able to move and rotate our character.

Now we just need to prevent the player from this using that bool check in the first person controller.

To prevent the rotation of the camera, create a new virtual camera called death camera and have that activated.

Also check the bool to make sure we can’t rotate the camera when dead as well.