How to use imported animation
I imported an animation for the player's death. I had a trigger which set itself true when the player died and it was working (trigger of animation in animator tab turned on when the player died), but the death animation didn't happen. When I went to look at the animation tab for the specific animation, I saw that all of the animation properties were 'missing'. I am new to animation in unity (and unity in general) so I have no idea what's causing this. I also tried playing around with it and the animation's 'animator controller' with no luck.
thanks
Answer by jmhoubre · Nov 14, 2021 at 09:35 PM
Good evening, here is the list of things to do or check: 1 - have an animator controller on the character. 2 - in the animator, have a trigger type parameter (left pane, 2nd tab). Copy the name of the parameter. 3 - in the animator, drag the death animation into the graph. 4 - from the AnyState state, add a transition to the dead state. 5 - select the transition, and in the right pane, add the condition corresponding to the trigger created. 6 - in the Health script which manages the health or death of the character, add a function:
using UnityEngine;
public class Health : MonoBehaviour
{
private int health;
private Animator animator;
private void Awake ()
{
animator = GetComponent<Animator> ();
}
private void Update ()
{
if (health <= 0)
{
PlayDeathAnimation ();
}
}
private void PlayDeathAnimation ()
{
// Warning : check the spelling of the parameter (it's best to copy in animator and paste in the script).
animator.SetTrigger ("MyDeathTrigger");
}
}
7 - call this function from Health.
Your answer
Follow this Question
Related Questions
How do I make my attack trigger work? 1 Answer
animator and script issue 0 Answers
How I can do stop animation when the key let go? 1 Answer
Interpolated movement in a circle 1 Answer
,Non-working animation - simple fix 0 Answers