Question by
klavyeadam · Oct 16, 2021 at 08:49 AM ·
uitimer
How to reset timer smoothly?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GameTime : MonoBehaviour { public Text hourText; public Text DayText; public float hour; public float day = 1; public bool isContinue;
// Start is called before the first frame update
void Start()
{
DayText.text = day.ToString();
}
// Update is called once per frame
void Update()
{
if (isContinue)
{
if (hour >= 5)
{
hour = 0;
hourText.text = string.Format("{0:0}", hour);
day++;
DayText.text = string.Format("{0:0}", day);
}
else
{
hour = Mathf.Clamp(hour, 0f, 5f);
hour += Time.deltaTime;
hourText.text = string.Format("{0:0}", hour);
}
}
}
public void Pause()
{
isContinue = false;
}
public void Continue()
{
isContinue = true;
}
}
The timer jumps from 5 to 0 too quickly in the UI. How can I make it smoother?
Comment
Your answer
Follow this Question
Related Questions
Race saving best times on different scene 0 Answers
How to stop a countdown timer and disable/stop everything in the scene? 1 Answer
Timer Countdown Pop Up Screen Before Scene "Starts" Please Help!! 2 Answers
Having trouble moving a UI panel 1 Answer
What do you insert in the "" area in this timer? (00:00) 1 Answer