GUI health bar issue

Im having issues with GUI texture health bar, currently the player is receiving damage and when health reaches 0 the level restarts, but the GUI textures do not change. The health bar is represented by 3 different textures but it displays only one (full health) even when damage is being applied.

here is my code, can someone please help me with this one, thanks

static var health:int=4; 

var health3: Texture2D;
var health2: Texture2D;
var health1: Texture2D;


function OnCollisionEnter(hit: Collision){
        if(hit.gameObject.collider){
           health = health - 1;
        }
   }


function Update () {


  if(health == 0)
           Application.LoadLevel("level01");

     
      var health=GameObject.Find("health");
        
        if(health==3){          
        
        guiTexture.texture = health3;
        
      
        }
      
        if(health==2){
        
        guiTexture.texture = health2;
        
            
        }  
        }

You don’t need to check health value in Update, as it only changes in OnCollisionEnter. So check it after the line health = health - 1;

However your script should work already, so I guess the collision event isn’t raised. Try adding some print(…) to see where the program goes.

ok, i removed the update function and the following line var.health=GameObject… it works as it did before, the textures don’t change. what is a print ()? sorry I’m new to scripting, if you can give an example please i can copy it into my script. thanks