using UnityEngine; using UnityEngine.UI; public class Timer : MonoBehaviour { private float timerValue; public Text timerText; void Start() { timerValue = 0.0f; timerText = GetComponent(); } void Update() { timerValue -= Time.deltaTime; if (timerValue <= 0.0f) { timerValue = 0.0f; // Handle end of timer } int minutes = Mathf.FloorToInt(timerValue / 60.0f); int seconds = Mathf.FloorToInt(timerValue % 60.0f); timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds); } void addSeconds(int seconds) { timerValue += (float) seconds; } }