Answer the question
In order to leave comments, you need to log in
How to add hero death animation to Unity 2D script?
I have a question, how to add the death animation of the hero to the script... The animation itself is ready, .. at the moment I have "Player"_(Hero) in my script. a method is written where lives are taken away (works well). when the number of lives = 0
, Collider2D is disabled, and the hero just falls to the bottom ... And I want the death animation to work instead of disabling the collider, I
wrote a method
( publuc void Death( )
{
anim.SetIneger("State", 4)// номер анимации в Аниматоре
}
Answer the question
In order to leave comments, you need to log in
- create a new GameObject with your own death animation
- initialize it in the Player class
public GameObject deathAnimation;
- after death, you create an animation in the place of the hero and hide his visibility. delete the hero object after the animation has ended (eg after 1f seconds)
Instantiate(deathAnimation, transform.position, Quaternion.identity);
gameObject.GetComponent().enabled = false;
gameObject.GetComponent().enabled = false;
Destroy(gameObject, 1f);
- pass the GameObject with animation through the inspector to the Hero code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question