Animation won't play all frames with damage script

So I been working on this damage script and I have the calculations working out completely fine. The problem is that it doesn’t like to switch the animations correctly as in, it will play the first frame of the animation and then it stays like that forever. I can’t even get the damage animation to switch to the dead one but my test variable says that isDead can be true… I don’t know if it’s the animation settings or what but I would really like this fixed!

Here is the player’s status script that is attached right now.

#pragma strict

var curHealth : float = 100f;
var healthBar: UnityEngine.UI.Slider;
var isAttacked: boolean;
var isDead: boolean;
//var maxHealth : float = 100f;
//var healthtext : GUIText;
function Start () {
	isAttacked = false;
	isDead = false;
	healthBar = UI.Slider.FindObjectOfType(UI.Slider);
//	healthRegen();
}

function Update () {

//	healthtext.text = curHealth + " / " + maxHealth;
	healthBar.value = curHealth;
	
	if(curHealth <= 0 ) {
		curHealth = 0;
	}

	if(curHealth >= 100) {
		curHealth = 100;
	}

	if (isAttacked == true) {
		animation.Play("note_damage01");
	}
	
	if(isDead == true){
		animation.Play("note_dead01");
		}

}
      function OnTriggerEnter(collider:Collider) {
      
          if (collider.tag == "Enemy"){
          	if(curHealth == 0) { 
          		isDead = true;
          		
          		}
          		else {
               		curHealth -= 10;
               		isAttacked = true;
               	}	
	}
}

Use this instead, it will provide more control more fluently. Seriously, I’d prefer not fixing your script because the answer is USE THE ANIMATOR CONTROLLER.
http://unity3d.com/learn/tutorials/modules/beginner/animation/animator-controller

It seems that for you animation.Play(“note_damage01”); plays a single frame. I cannot explain this behavior.

Anyway, script lesson time:

  1. if statements execute if the statement in the brackets is true. A bool does not ened a comparison, in fact a comparison TURNS into a bool. So

    if(isAttacked == true)

should be

 if(isAttacked)
  1. You should use the else statement. Mostly for conditions where you’ve already learned the OPPOSITE is true and don’t want to execute the next one. So:

    if(curHealth <= 0 ) {
    curHealth = 0;
    }
    if(curHealth >= 100) {
    curHealth = 100;
    }

should be

 if(curHealth <= 0 ) {
curHealth = 0;
}
 else if(curHealth >= 100) {
curHealth = 100;
}
  1. This si something you learn as you look through examples, but there is a function that can truncate the above code. It is in the Mathf library.

The above if can be shortened to ONE line:

curHealth = Mathf.Clamp(curHealth, 0f, 100f);

3PS. You probably don’t want the healthbar to show a value that hasnt been clamped, so it should be placed LOWER than the clamp line.