Advertisement
aandnota

GUITimer

Feb 28th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private var textMesh:TextMesh;
  2. var textTime : String;
  3.  
  4. private var startTime;
  5. private var restSeconds : int;
  6. private var roundedRestSeconds : int;
  7. private var displaySeconds : int;
  8. private var displayMinutes : int;
  9.  
  10. var countDownSeconds : int;
  11.  
  12. function Start() {
  13.     startTime = Time.time;
  14.     textMesh = GetComponent(TextMesh);
  15. }
  16.  
  17. function Update () {
  18.    
  19.     var guiTime = Time.time - startTime;
  20.     restSeconds = countDownSeconds - (guiTime);
  21.  
  22.     if (restSeconds == 0) {
  23.         if(Time.timeScale == 1.0){
  24.             Time.timeScale = 0.0;
  25.         }
  26.     }
  27.     if (Time.timeScale == 0.0){
  28.         if(Input.GetButtonDown("load")){
  29.             Application.LoadLevel(0);
  30.             Time.timeScale = 1.0;
  31.         }
  32.     }
  33.  
  34.    
  35.     roundedRestSeconds = Mathf.CeilToInt(restSeconds);
  36.     displaySeconds = roundedRestSeconds % 60;
  37.     displayMinutes = roundedRestSeconds / 60;
  38.  
  39.     textTime = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
  40.     textMesh.text = textTime;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement