Unity animation bug?

Hello, i am have code

if (Health > 0){      Demon.PlayOneShot(PainSound[Random.Range (0, PainSound.Length)]);
DemonAnimator.SetTrigger ("Pain");
}else
{
isDead = true;
Demon.PlayOneShot(Die);
DemonAnimator.SetTrigger ("Die");
}

But, if Health change to 0, or below 0, animation “Die” plays once, then plays animation “Pain” again.
WHY?

There’s a chance something is setting health back to above 0 by the next frame, causing the pain anim to play. since you already have a isDead boolean, maybe just add that to the conditions to check to play the pain anim.

if(Health > 0 && !isDead) {...

this way, the pain anim will not trigger as long as isDead is true, which if right you already set to true when health reaches 0 or less.

No, is not work(

public void TakeDamage(int Amount){
       if (isDead == false){
           Health -= Amount;
           StartCoroutine(Pain());
       }
   }

Even in the method of producing damage it is worth checking “isDead”;

guess youll have to start putting print statements to pinpoint whats firing in our code.