Search Unity

Timer Help

Discussion in 'Scripting' started by brandon199511, Dec 31, 2011.

  1. brandon199511

    brandon199511

    Joined:
    Sep 21, 2010
    Posts:
    268
    Edit: FIXED

    Just call for a function in the start() as so...

    Code (csharp):
    1.  
    2. //variable
    3. var timerThreeT : int = 3;
    4.  
    5. //start function
    6. function Start()
    7. {
    8.      TimerThree();
    9. }
    10.  
    11. // This code calls every frame
    12. function Update ()
    13. {
    14.         // Keep the countdown from stopping and just reset it once it hits zero
    15.         if(timerThreeT <= 0)
    16.     {
    17.         timerThreeT = 3;
    18.     }
    19. }
    20.  
    21. //Timer Function
    22. function TimerThree()
    23. {
    24.     while(timerThreeT > -1)
    25.     {
    26.         // wait for 1 second
    27.         yield WaitForSeconds(1);
    28.         // reduce the time
    29.         timerThreeT --;
    30.     }
    31. }
    32.  


    Once you have all that just change the value of the count down when you want to use it, like this:
    Code (csharp):
    1.  
    2.  timerThreeT = 3;
    3.  
    Then print it in GUI.
     
    Last edited: Dec 31, 2011