I have set my death animation wrapmode become once but it still play loop. How can I play it just once before destroyed ?
[34369-animation+problem.png|34369]
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;
}