Answer the question
In order to leave comments, you need to log in
How to make a reverse timer with minutes?
Good day. I want to make a reverse timer in the game, with minutes like this: 01:30 (minute:seconds).
The timer itself in seconds is obtained in the simplest way to do this:
public float timer = 90f;
void Update()
{
timer -= Time.deltaTime;
if(timer <= 0.0f)
{
Debug.Log("The END");
}
}
Answer the question
In order to leave comments, you need to log in
For such a case, it's better to use DateTime and TimeSpan along with formatting patterns :
using System;
using UnityEngine;
public class TimerTest : MonoBehaviour
{
public float timer = 90;
private DateTime timerEnd;
private void Start()
{
timerEnd = DateTime.Now.AddSeconds(timer);
}
private void Update()
{
TimeSpan delta = timerEnd - DateTime.Now;
Debug.Log(delta.Minutes.ToString("00") + ":" + delta.Seconds.ToString("00"));
if (delta.TotalSeconds <= 0)
{
Debug.Log("The END");
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question