#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();
}

 

'유니티3D > 예제' 카테고리의 다른 글

plane size 동적할당  (0) 2013.08.21
HPBar  (0) 2013.08.20
PaddleGame  (0) 2013.08.15
MonsterCtrl.cs  (0) 2013.08.12
메카님방식  (0) 2013.08.12

+ Recent posts