- Home /
Question by
Robby-rEINEWALD · Oct 27, 2014 at 08:22 AM ·
animationdeathoncewrapmode
Death animation play more than once
I have set my death animation wrapmode become once but it still play loop. How can I play it just once before destroyed ?
animation problem.png
(22.1 kB)
Comment
Best Answer
Answer by sevensixtytwo · Oct 27, 2014 at 08:33 AM
Your die() function is being called repeatedly during the two seconds before it is Destroyed. Add a boolean to indicate whether the animation can play again. Like so:
function die() {
if (!isDead) {
animation.Play("death");
Destroy(gameObject,2);
isDead = true;
}
}
The animation won't play anymore after the first call because the boolean "isDead" is now true.
another way is:
if (health <= 0 && !isDead) {
die();
isDead = true;
}
Thank you so much, it works. I'm still newbie in unity so I don't know much about it logics.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170040im_/https://answers.unity.com/themes/thub/images/avi.jpg)