using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using UnityEngine.UI; public class Clock : MonoBehaviour { public float timeRemaining = 0; //keeps track of remaining time public bool timeIsRunning = true; //bool to indicate if the timer is running public TMP_Text timeText; //text to hold the time void Update() { if(timeIsRunning) { if(timeRemaining >= 0) { timeRemaining += Time.deltaTime; //if timeRemaining >=0 increase time DisplayTime(timeRemaining);//show increased time } } } void DisplayTime(float timeToDisplay) { timeToDisplay += 1; //adjust time to display float minutes = Mathf.FloorToInt (timeToDisplay / 60); //minutes from total seconds float seconds = Mathf.FloorToInt (timeToDisplay % 60); //seconds remaining after minutes found timeText.text = string.Format("{0:00}:{1:00}", minutes, seconds); //show formatted time } }