Problem with HealthBar

Well im new here guys.

I want to tell you that I am making a game for the iphone and well I have some problems but the most important now is the health bar, here is the code:

// Player goes here:

var Warrior: GameObject;

//Here are the textures of the health

var Health1: Texture2D;
var Health2: Texture2D;
var Health3: Texture2D;

//Times Dead

var fall = 0;

//Some Code

function Update () {

// If the player falls, the healthbar will decrease

if(Warrior.transform.position.y < -2 )

{

gameObject.Find ("Health");

//Change the HealthBar

guiTexture.texture = Health2;

fall = 1; //Now the fall times increases to 1, untill here all is ok

}
}

if(Warrior.transform.position.y < -2 && fall == 1){

gameObject.Find ("Health");

//Change the HealthBar

guiTexture.texture = Health3;

}

Does anybody see a problem there?

My code does not has errors but the bar only decreases to Health2 if I fall again it doesnt decrease to Health3.

Some help?

That code is a bit weird.

  1. Why the Finds? You're not using the "Health" thingy-ma-jig anyways.
  2. The last if-statement is outside the Update function.
  3. Putting the last if-statement inside the Update function will give you a health bar with Health3 when y < -2, because you will set fall = 1 and y < -2 will still be correct.