Guest User

Untitled

a guest
Jul 16th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. // the textfield to update the time to
  2. private var textfield:GUIText;
  3. static var isLevelFinished = false;
  4. // time variables
  5. public static var allowedTime:int = 15;
  6. public static var currentTime = allowedTime;
  7.  
  8. function Awake()
  9. {
  10. // retrieve the GUIText Component and set the text
  11. textfield = GetComponent(GUIText);
  12.  
  13. UpdateTimerText();
  14.  
  15. // start the timer ticking
  16.  
  17. TimerTick();
  18. }
  19.  
  20. function UpdateTimerText()
  21. {
  22. // update the textfield
  23. textfield.text = currentTime.ToString();
  24. }
  25.  
  26. function Exit()
  27. {
  28. Application.LoadLevel(2);
  29. }
  30.  
  31. static var timeup = false;
  32. var audio1 : AudioSource;
  33.  
  34. var audio2 : AudioSource;
  35.  
  36.  
  37. function TimerTick()
  38. {
  39.  
  40. // while there are seconds left
  41. while(currentTime > 0 )
  42. {
  43. if (currentTime==6)
  44. {
  45. audio1.Play();
  46. }
  47. // wait for 1 second
  48. yield WaitForSeconds(0.6);
  49.  
  50. // reduce the time
  51. if(isLevelFinished){
  52. currentTime--;}
  53.  
  54. UpdateTimerText();
  55.  
  56. }
  57.  
  58.  
  59. audio2.Play();
  60. timeup = true;
  61. Invoke("Exit",2);
  62. }
Add Comment
Please, Sign In to add comment