I have this timer GUI for an air supply indicator only I’m having difficulty trying to figure out why when I pause the timer it keeps counting down even though the GUI indicator bar has stopped. Here is the code I’m using:
var startTime : float; // (in sec)
var timeRemaining : float; // (in sec)
var percent : float;
var clockBG : Texture2D;
var clockFG : Texture2D;
var buttonTexture: Texture2D;
var pauseButtonTexture: Texture2D;
var clockBGMaxWidth : float; // the starting width of the foreground bar
function Awake()
{
//startTime = 20.0;
clockBGMaxWidth = clockFG.width * 1;
}
function Update ()
{
if(!clockIsPaused)
{
// make sure the timer is not paused
DOCountdown();
}
}
function OnGUI()
{
var newBarWidth : float = (percent/105) * clockBGMaxWidth; // this is the width that the foreground bar should be
GUI.BeginGroup (new Rect(0, 120, newBarWidth, clockBG.height));
GUI.DrawTexture (Rect (118, 0, clockBG.width * 1, clockBG.height), clockBG);
GUI.EndGroup ();
GUI.BeginGroup (new Rect(0, 0, clockFG.width * 1, clockFG.height));
GUI.DrawTexture (Rect (0, 0, clockFG.width * 1, clockFG.height), clockFG);
GUI.EndGroup();
if (GUI.Button(Rect(735,20,50,50), buttonTexture, "")){
Application.LoadLevel("ThreeD_Overview");
}
if (GUI.Button(Rect(70,440,64,32), pauseButtonTexture, "")){
//Pause Timer
clockIsPaused = true;
}
}
function DOCountdown()
{
timeRemaining = startTime - Time.time;
percent = timeRemaining/startTime * 100;
if (timeRemaining < 0)
{
timeRemaining = 0;
clockIsPaused = true;
//TimeIsUp();
Debug.Log("Time is up!");
//Application.LoadLevel (0);
}
//ShowTime();
}