Question by 
               kaimelis · May 12, 2016 at 10:49 AM · 
                c#timetimertimer countdown  
              
 
              Clock doesn't stop when reaches 0.0. Can you help me with this.
So I have the problem that I never reach the else statement in update. And also i want the clock to stop at 0.0. The startTime is in seconds. If you make it 90.0f you will have 1.30minute. The problem is i need to stop this clock when reaches the 0:0.0. Thank you in advance
 public class TImer : MonoBehaviour
 {
 
     public Text TimerText;
     private float startTime = 3.0f;
     private bool start = false;
     private float _time;
     private float _minutes, _seconds;
 
     // Use this for initialization
     void Start ()
     {
         start = false;
         startTime = 3.0f;
     }
     
     // Update is called once per frame
     void Update ()
     {
        // if (start)
       //  return;
         if (startTime > 0.0f)
         {
             _time = startTime - Time.time; // ammount of time since the time has started
             _minutes = (int)_time / 60;
             _seconds = _time % 60;
             TimerText.text = _minutes + ":" + _seconds.ToString("f1");
         }
         else
             Debug.Log("we are here"); 
     }
 
     private void CheckGameOver()
     {
         Debug.Log("gameover");
     }
 
     public void StartTime()
     {
         TimerText.color = Color.black;
         start = true;
     }
 
              
               Comment
              
 
               
              Answer by kaimelis · May 12, 2016 at 11:17 AM
Fixed it. so in start method I made that time is startTime
 oid Start ()
     {
         start = false;
         _time = startTime;
     }
 
               And in Update method I said if _time is bigger then 0.0f then run clock and stop if it's less.
 void Update ()
     {
        // if (start)
       //  return;
         if (_time > 0.0f)
         {
             _time = startTime - Time.time; // ammount of time since the time has started
             _minutes = (int)_time / 60;
             _seconds = _time % 60;
             TimerText.text = _minutes + ":" + _seconds.ToString("f1");
         }
         else
         {
             CheckGameOver();
         }
     }
 
              Your answer