#pragma strict
var isPaused : boolean = false; var startTime : float; var timeRemaining : float; var percent:float; var clockBG:Texture2D; var clockFG:Texture2D; var clockFGMaxWidth:float; //initial value of bar;
function Start () { startTime = 120.0; clockFGMaxWidth = clockFG.width; }
function Update () { if(!isPaused) { DoCountDown(); } }
function DoCountDown() {
timeRemaining = startTime - Time.time; percent = timeRemaining/startTime * 100; if(timeRemaining < 0) { timeRemaining = 0; isPaused = true; TimeIsUp(); } /*if(timeRemaining < 0) { timeRemaining = 0; isPaused = true; TimeIsUp(); } */ ShowTime(); Debug.Log("Time remaining = " + timeRemaining); }
function PauseClock(){
}
function UnpauseClock(){ isPaused = false; }
function ShowTime(){
var minutes : int; var seconds : int; var timeStr : String; minutes = timeRemaining/60; seconds = timeRemaining%60; timeStr = minutes.ToString() + ":"; timeStr += seconds.ToString("D2"); guiText.text = timeStr; }
function TimeIsUp(){ Debug.Log("Time is up"); }
function OnGUI() { var newBarWidth:float = (percent/100) * clockFGMaxWidth; var gap:int = 20; GUI.BeginGroup(new Rect(Screen.width - clockBG.width - gap,gap,clockBG.width, clockBG.height)); GUI.DrawTexture(Rect(0,0,clockBG.width, clockBG.height),clockBG); GUI.BeginGroup(new Rect(5,6,newBarWidth,clockFG.height)); GUI.DrawTexture(Rect(0,0,clockFG.width, clockFG.height),clockFG); GUI.EndGroup(); GUI.EndGroup(); }
|