countdow timer

this script is confusing me i asked my teacher and he told me to “put the timer -=Timer.deltaTime; inside if (timer >0) statement and inside if timer < 0f set text.text to “0”,so it displays zero if timer is less than 0” anyone has an idea what that means?

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class Timer : MonoBehaviour{

 float timer = 30.0f;
 public Text text;
 public GameObject GameOverText;
 public bool enable;
 void Update()
 {
     timer -= Time.deltaTime;
     text.text = "" + Mathf.Round(timer);
     if (timer < 0f )

     {
         GameOverText.gameObject.SetActive(true);
     }
 }

}

The idea your teacher was going for is that once time runs out, we want to stop decreasing the timer. If we don’t, the timer will keep decreasing and the text will go into the negatives.

// We want to keep decreasing the timer while there is time remaining
if (timer > 0f)
{
     timer -= Time.deltaTime;

     if (timer <= 0f)
     {
         // If the new time is < 0, then we've now run out of time. 
         // We should now make sure the timer text says zero,  and activate the game over text
         text.text = "0";
         GameOverText.gameObject.SetActive(true);
     }
     else
     {
         // There's still some time left, so we just want to make sure the text gets updated
         text.text = "" + Mathf.Round(timer);
     }
}