The problem here is the type of lf: it should be declared as float. I rewrote your script and there it goes:
// declare the vars as private unless you want them to appear in the Inspector
// also always declare the types of each variable, or you can get in trouble again
private var bar : boolean;
private var lf:float = 100; //currentHealth
private var mxlf:float = 100; //maxHealth
private var barlf:float; //length of healthbar
// I altered this function to never let the life negative
// the type of lf is float, or you would end with a too fast bar
function Update(){
if (bar){
if (lf>1){
lf -= Time.deltaTime * 2; // this is the bar velocity
} else
{
// ...
// this part of the IF will be executed when the life reachs zero
// do whatever you want with your dead character here
// ...
print("GAME OVER");
}
}
}
function Start () {
barlf = (Screen.width/ 2 /(mxlf / lf));
bar = false;
}
function OnTriggerEnter (other : Collider) {
bar = true;
}
function OnTriggerExit (other : Collider) {
bar = false;
}
function OnGUI (){
if(bar){
GUI.color = Color.yellow; // I couldn't alter the background color, only the text
// this box will be reduced according to the life remaining
if (lf>1) GUI.Box (Rect(10, 10, barlf*lf/mxlf, 20),"");
// Mathf.Floor returns the integer part of lf
GUI.Box (Rect(10, 10, barlf, 20), Mathf.Floor(lf) + "/" + mxlf);
}
}
function AdjustCurrentHealth(adj){
lf += adj;
if ((lf > 0) && (lf <= mxlf)){
barlf = (Screen.width/ 2 / (lf / mxlf));
}
else
{
barlf = 0;
}
}