Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // the textfield to update the time to
- private var textfield:GUIText;
- static var isLevelFinished = false;
- // time variables
- public static var allowedTime:int = 15;
- public static var currentTime = allowedTime;
- function Awake()
- {
- // retrieve the GUIText Component and set the text
- textfield = GetComponent(GUIText);
- UpdateTimerText();
- // start the timer ticking
- TimerTick();
- }
- function UpdateTimerText()
- {
- // update the textfield
- textfield.text = currentTime.ToString();
- }
- function Exit()
- {
- Application.LoadLevel(2);
- }
- static var timeup = false;
- var audio1 : AudioSource;
- var audio2 : AudioSource;
- function TimerTick()
- {
- // while there are seconds left
- while(currentTime > 0 )
- {
- if (currentTime==6)
- {
- audio1.Play();
- }
- // wait for 1 second
- yield WaitForSeconds(0.6);
- // reduce the time
- if(isLevelFinished){
- currentTime--;}
- UpdateTimerText();
- }
- audio2.Play();
- timeup = true;
- Invoke("Exit",2);
- }
Add Comment
Please, Sign In to add comment