How to use apply damage?

Okay I’ve got a battery gui but i want it so that when i click on an object that it would add to the battery and also update the gui as well.

Here is the code I have.

var remaining : float = 0;
var pos : Vector2 = new Vector2(20,40);
var size : Vector2 = new Vector2(60,20);
var battery : Texture2D;
var energy : Texture2D;

function OnGUI()
{
    GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), battery);
    GUI.DrawTexture(Rect(705, 355, (size.x-15)- (45 *Mathf.Clamp01(remaining)), size.y-10.5), energy);
}

function Update()
{
       remaining=Time.time *0.01;
}

not sure if you want battery image to fill up as you collect more batteries or just a new battery image to show up representing how many you have, the script below is for filling up as you collect more:

place this within your current script:

static var batteryAmount : int;

var batteryState1 : Texture2D;

var batteryState2 : Texture2D;

var batteryState3 : Texture2D;

function OnGui(){

if (batteryAmount == 1){

GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), batteryState1);

}else if (batteryAmount == 2){

GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), batteryState2);

}else if (batteryAmount == 3){

GUI.DrawTexture(Rect(pos.x, pos.y, size.x, size.y), batteryState3);

}

}

you get the idea.

for the collection if you want it on click create a new script on place it on the object you want to collect.

function OnMouseOver(){

if (Input.GetButtonUp(0){

name of original script.batteryAmount++;

}

}

that should work, i think. any problems let me know

(there maybe some mistakes to the actual writing as i just wrote it then =P)