I am trying to make a timer and display the time, and I’ve got it. However, there would be a little bit of error.
As you can see from the image, my timer starts at 60 (that is not the problem), but when it jumps from 60 to 59, it is faster than others. For example, 59 to 58 would be slower (in the real time seconds), and 60 to 59 would be faster by some. I think it is problems about frames, but I am not sure how I can solve this.
Here are my codes:
public class Timer : MonoBehaviour
{
public Text text;
float timer;
void Awake ()
{
timer = 60;
}
void Update ()
{
if (Time.timeScale != 0)
{
timer -= Time.deltaTime;
text.text = "Time: 0:" + timer.ToString ("00");
}
}
}
public class TimeDelay : MonoBehaviour
{
float theTime;
void Awake ()
{
Time.timeScale = 0;
}
void Update ()
{
if (Input.GetKey (KeyCode.A))
Time.timeScale = 1;
}
}