Progress Bar On Button Press - Pick Up From Last Position

Hey guys, I’m not new to the forums/answers exactly, but it’s the first time I myself have needed to ask a question. I usually google around and find an answer to my question without having to ask one myself.

Well, here goes. I have this progress bar that starts once I press a button. I’m trying to make it so that even after I let go of said button, it picks up from where it left off on the progress bar. At the moment, if I let go of the action button and then press it again the progress bar just starts all over again. It’s kind of annoying and a killer to my game mechanics. The bar itself also decreases back to 0 over time if left alone long enough (which is intentional).

Here’s the code in question:

var barDisplay : float = 0;
var progressBarEmpty : Texture2D;
var progressBarFull : Texture2D;
private var barStarted : boolean = false;
private var barStartTime : float = 0;
private var barEndTime : float = 0;
var wall : GameObject;
var drunkObjects : GameObject;
var soberObjects : GameObject;

function Start()
{
	barDisplay = 0;
	barStarted = false;
	drunkObjects.SetActiveRecursively(false);
	soberObjects.SetActiveRecursively(true);
}

function OnGUI()
{
	
	// draw the background:
	GUI.BeginGroup (new Rect(Screen.width / 2 - 55, 0, 110, 40));
	GUI.Box (Rect (0,0, 110, 40),progressBarEmpty);
	
	// draw the filled-in part:
	GUI.BeginGroup (new Rect (0, 0, 110 * barDisplay, 40));
	GUI.Box (Rect (0,0, 110, 40),progressBarFull);
	GUI.EndGroup ();
	
	GUI.EndGroup ();
	
}

function Update()
{
	// for this example, the bar display is linked to the current time,
	// however you would set this value based on your desired display
	// eg, the loading progress, the player's health, or whatever.
	
	if(Input.GetButton("Action"))
	{
		if( barStarted == false )
		{
			barStarted = true;
			barDisplay = 0;
			barStartTime = Time.time;
		}
		else
		{
			var barCurTime : float = Time.time;
			barDisplay = (barCurTime - barStartTime) * 0.5;
			barEndTime = barCurTime;
			if(barDisplay >= 1)
			{
				drunkObjects.SetActiveRecursively(true);
				soberObjects.SetActiveRecursively(false);
				wall.renderer.enabled = true;
			}
		}
	}
	else
	{
		barStarted = false;
		if(barDisplay > 0)
		{
			barCurTime = Time.time;
			barDisplay += (barEndTime - barCurTime) * 0.0002;
			if(barDisplay <= 0)
			{
				drunkObjects.SetActiveRecursively(false);
				soberObjects.SetActiveRecursively(true);
				wall.renderer.enabled = false;
			}
		}
	}
}

I picked up some of the code from one of the questions in here which is what most of the commented out parts are all about. Any steer in the right direction would be appreciated.

in youre else statement remove the line “barStarted = false;”.