Help with timebar

I’m not able to finalize the script below. Please, I need instructions objective.

My problems:

  • The bar is not declining, just count the numbers
  • I would make the countdown more slowly (0.1 * time.deltaTime ever used, and it did not work)
  • How do I know that the count reached “0” in order to transport the player and reset the game?

Script:

var bar : boolean;
var lf = 100; //currentHealth
var mxlf = 100; //maxHealth
var barlf; //length of healthbar

function Update(){
	if (bar == false){
		return;
	}
	else
	lf -= Time.deltaTime * 0.1;//still fast - I need to count time in seconds
}

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 == false)
	return;
	GUI.Box (new Rect (10, 10, barlf, 20), lf + "/" + mxlf);
	GUI.backgroundColor = Color.yellow;//not working
}

function AdjustCurrentHealth(adj){
	lf += adj;
	if ((lf > 0) && (lf <= mxlf)){
		barlf = (Screen.width/ 2 / (lf / mxlf));
	}
	else
	{
		barlf = 0;
	}
}

Please, if you answer, return later to this topic for any questions that I have.

well to slow it down to count down by seconds you simply just say Time.deltaTime * 1

and guessing on the count hitting zero…

if(lf <= 0){
//reset what ever you want
}

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;
    }
}