I wrote a death animation script:
#pragma strict
var health: float;
var healthdrop: float;
var starthealth: float;
var person: Animation;
function Start () {
health = starthealth;
}
function Update () {
if(health <= 0){
person.Play("death");
}
}
function OnTriggerEnter (other:Collider) {
if(other.gameObject.tag == "Bullet"){
Destroy(other.gameObject);
health = health - healthdrop;
}
}
I set starthealth to 100, healthdrop to 20 and I set the animation in the inspector as this:
As you can guess, I want to play the animation once the health hits 0, but it plays the animation immediately after scene starts.
What can I do to run the animation if (health <= 0) ?