How to pick up battery to open door?

Hi guys, my game is about a maze that is character have to collect enough battery to open the door, here is my script about the open door, can someone help me scripts for battery? Another thing is how we put a battery charge bar on the screen so player will know he has enough 4 batteries to open the door? Please help me, thank guys.

var door: Transform;

var angleOpen: int;
var angleClose: int;
var speedOpen: int = 1000;

function OnTriggerStay(other:Collider){
	if (door.transform.localEulerAngles.y < angleOpen){
		door.transform.Rotate(Vector3.up*Time.deltaTime*speedOpen);
	}
}

Make the battery collider be a trigger. The Colliders of the Playermodel must have the Tag Player.
Attached this as a Script on it:

function OnTriggerEnter(var col : Collider)
    {
    if(col.tag == "Player")
    {
    col.GetComponent(PlayerScript).Battery++;
    Destroy(col.gameObject);
    }
    }

Attached the Variable Battery as public to the PlayerScript(if you havent a PlayerScript make ones in js).
Then write in your Doorscript this:

//this Variable outside the function
public var pl: PlayerScript;

if(door.localEulerAngels.y<angelOpen&& pl.Battery>=4)

to show it on the Screen write in your PlayerScript:

function OnGUi()
{
GUI.label(Battery.ToString(),Rect(your Position));
}

To have a Bar write instant of the Gui label this:

GUI.texture(theBarTexture,Rect(posx,posy,widht*Battery,height));

This is much esay because you mustn have a texture for every Value.

If Batterys equal zero the bar widht*zero is zero

If Batterys equal one the bar widht* one is your size multiplicatet with one

Step 1. make a GUI Texture like your battery for four different levels. eg.: for 20 percnt, 40 percent, 60 percent and so on.

Step 2. Write this piece of pseudecode
var h00: Texture2D;
var h10: Texture2D;
var h20: Texture2D;
var h30: Texture2D;
var h40: Texture2D;
var h60: Texture2D;
var h80: Texture2D;
var h100: Texture2D;

var Bhealth=100;

function Update(){

var g_health= gameObject.Find(“GUI_Health”);
if(Bhealth>80)
{
g_health.guiTexture.texture= h100;
return;
}
if(Bhealth>70)
{

g_health.guiTexture.texture= h80;
 }
 
 else if(Bhealth>50)
 {
 g_health.guiTexture.texture= h60;
 return;
 }
 else if(Bhealth>30) 
 {
 g_health.guiTexture.texture= h40;
 return;
 }
else if(Bhealth>20)
 {
 g_health.guiTexture.texture= h30;
 return;
 }
 else if(Bhealth>10)
 {
 g_health.guiTexture.texture= h20;
 return;
 }
else if(Bhealth>5)
 {
 g_health.guiTexture.texture= h10;
 return;
 }
 else if(Bhealth<=0)
 {
 g_health.guiTexture.texture= h00;
 
 return;
 }

}

something like this…

try mate.