Timer Bar Modifications

Hello, I'm using the following script and it works fine but I'm lost as to how to change two things.

  1. Instead of counting up, what math would I use in the Update function to start full and count down?

  2. I have pick ups in my levels that add to the player's time. How would I target this script and add 25 seconds back on to the countdown? Currently in my collision.js when a collision occurs with an object tagged "Battery" I add 25 to a variable named PLAYER_LIFE.

Also, is this method processor intensive? Eventually I'd like to release on the iPhone.

Thanks for any help.

var barDisplay : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(200,20);
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
var fullVariable : float = 200;
var decreaseRate : float = 1.00;

function OnGUI()
{

    // draw the background:
    GUI.BeginGroup (new Rect (pos.x, pos.y, size.x, size.y));
        GUI.Box (Rect (0,0, size.x, size.y),progressBarEmpty);

        // draw the filled-in part:
        GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
            GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);
        GUI.EndGroup ();

    GUI.EndGroup ();

} 

function Update()
{
    barDisplay = fullVariable - Time.time * decreaseRate;
}

depends what "full" is in your update function.

barDisplay = FullVariable - Time.time * DecreaseRate;

It's simple mathmatics, subtract and add. Been caught up with something like this myself, kept trying more complex solutions when the answer was so simple. For accessing variables in different scripts you either make them static variables or use GetComponent

and for the final edit your problem is this

GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
GUI.Box (Rect (0,0, size.x, size.y),progressBarFull);

dont resize the group resize the box the texture is in.

GUI.BeginGroup (new Rect (0, 0, size.x, size.y));
GUI.Box (Rect (0,0, size.x * barDisplay, size.y),progressBarFull,ScaleMode.StretchToFill);

Multiplying things by a decimal is a good way of saying percentage. If I multiply 100 * 0.95, I'll get 95% of 100, or 95. I commonly do this to get a percentage of screen space on different resolutions. Screen.width * 0.5 = 50% of the screen width.

Anyways... Except rather than what Bobadebob did, I would just do:

FullVariable -= 1.0 * Time.deltaTime;

This means FullVariable will go down by 1 per second. (Any time you multiply a value by Time.deltaTime, you can expect it to mean that whatever you're changing will change by that amount per second, if it's inside of Update).