Help with counting frames

I want to allow a GUI to stay on for a few frames after the player has colleced 4 batteries, so I increment framesCounted in Update() if charge >=4.

It is only incrementing once, but not every frame as expeceted. Can anybody help with this?

var doorIsOpen: boolean = false;
var doorTimer:float = 0;
private var currentDoor:GameObject;
var doorOpenTime: float = 3;
var doorOpenSound:AudioClip;  //How do I assign a audio clip here? = doorSlideOpen;
var doorShutSound:AudioClip; // = doorSlideShut;
var batteryCollect:AudioClip; // = battery_collect;
var waitFrames: int = 200;
//end of variable declarations
function Update () 
{ 
			
var framesCounted : int = 0;
Debug.Log(" framesCounted = "+ framesCounted + " BatteryCollect.charge = " +BatteryCollect.charge);
var hit : RaycastHit; 
		if(BatteryCollect.charge>=4) 
		{
		framesCounted ++; //this should update every frame after 4 batteries are collected.
		}
		if (BatteryCollect.charge>=4  Physics.Raycast(transform.position, transform.forward, hit, 5))
		{ 
			Debug.Log("The charge is now >= 4 and framesCounted = "+ framesCounted);
			if(framesCounted > waitFrames) {GameObject.Find("battery GUI").GetComponent(GUITexture).enabled=false;}
			Debug.Log("hit contains hit point: "+ hit.point) ;
			if(hit.collider.gameObject.tag=="outpostDoor"  doorIsOpen == false)
			{
				currentDoor = hit.collider.gameObject;
				Door(doorOpenSound,true, "dooropen", currentDoor);
			}
		}
			if(doorIsOpen) //this could also be simply if(doorIsOpen) without the explicit check
			{
				//Debug.Log("function Update() got called and doorIsOpen is true");
				//Debug.Log(currentDoor + " is the current door. doorIsOpen = " + doorIsOpen);
				doorTimer += Time.deltaTime;
				if (doorTimer > doorOpenTime)
				
				{
					//shutDoor();  replaced with line below
					Debug.Log("doorTimer > doorOpenTime.  Shutting Door = " + currentDoor );
					Door(doorShutSound, false, "doorshut", currentDoor);
					doorTimer = 0;
				}
			}	
			else 
			{
				//Debug.Log("function Update() got called and doorIsOpen is false");
				//Debug.Log("doorTimer = "+ doorTimer+ " and doorOpenTime = "+ doorOpenTime);
			}
	//}
}
function Door(aClip : UnityEngine.AudioClip, openCheck : boolean, animName : String, thisDoor: GameObject)
{
	Debug.Log("Calling function Door(aClip = " + aClip + "openCheck = " + openCheck+ "animName "  +animName + " thisDoor =  " + thisDoor); 

	audio.PlayOneShot(aClip);
	doorIsOpen = openCheck;
	thisDoor.transform.parent.animation.Play(animName);
	// thisDoor.animation.Play(animName); WON'T work b/c thisDoor does not have an animation
	//the animation belogs to the pareent object, so we must explicitly invoke the parent's animation
}
function OnTriggerEnter(collisionInfo : Collider)
{
	if(collisionInfo.gameObject.tag == "battery")
	{
		BatteryCollect.charge++;
		audio.PlayOneShot(batteryCollect);
		Destroy(collisionInfo.gameObject);
	}
}
@script RequireComponent(AudioSource) //this is to ensure that the AudioSource compoenent
//has been added just in case the object does not already have it

/*function OpenDoor //this one and shutDoor were replaced with func Door
{
	var myOutpost:GameObject = GameObject.Find("outpost");
	audio.PlayOneShot(doorOpenSound);
	openDoor = true;
	myOutpost.animation.Play("dooropen");
}

function shutDoor()  //this one and openDoor were replaced with func Door
{
	audio.PlayOneShot(doorShutSound);
	doorIsOpen = false;
	var myOutpost : GameObject = GameObject.Find("Outpost");
	myOutpost.animation.Play("doorshut");
} */

Your var declaration is currently in your update function, so you’re essentially telling the program to create and set a framesCounted var to 0, every single frame.

What you really want to do is declare the var outside of the update function.

Change it to this:

var framesCounted : int = 0;   // outside update function


function Update(){
...
...
framesCounted++;   // inside update function
...
...
}