Advertisement
Guest User

Timer

a guest
Oct 13th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //TIMER
  2. //*************************************************************************************************************************************
  3. private var startTime : float;
  4. private var restSeconds : int;
  5. private var roundedRestSeconds : int;
  6. private var displaySeconds : int;
  7. private var displayMinutes : int;
  8.  
  9. var countDownSeconds : int;
  10.  
  11. function Awake() {
  12.     startTime = Time.time;
  13. }
  14.  
  15. function OnGUI () {
  16.     //make sure that your time is based on when this script was first called
  17.     //instead of when your game started
  18.     var guiTime = Time.time - startTime;
  19.  
  20.     restSeconds = countDownSeconds - (guiTime);
  21.  
  22.     //display messages or whatever here -->do stuff based on your timer
  23.     if (restSeconds == 60) {
  24.         print ("One Minute Left");
  25.     }
  26.     if (restSeconds == 0) {
  27.         print ("Time is Over");
  28.         Time.timeScale = 0;
  29.     }
  30.  
  31.     //display the timer
  32.     roundedRestSeconds = Mathf.CeilToInt(restSeconds);
  33.     displaySeconds = roundedRestSeconds % 60;
  34.     displayMinutes = roundedRestSeconds / 60;
  35.  
  36.     var text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
  37.     GUI.Label (Rect (400, 25, 100, 30), text);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement