Hey guys, i am making a CountDown Timer, and it work, but not as i wanted. I made it very simple in C#. It’s basically a float that is changed over time, and it is shown in a text. If i set the float to 900 (15 minutes), then the text is going to be shown like 900 normally. What i want to do is, if i set the float to 900, then in the text, it will show something like 15:00. How would i do that? I have no idea of how to start.
This is my script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public float timeLeft = 900.0f;
public Text text;
bool clock;
private float mins;
private float secs;
void Update()
{
if (timeLeft > 0 && clock == false)
{
clock = true;
StartCoroutine(Wait());
}
}
IEnumerator Wait()
{
timeLeft -= 1;
UpdateTimer();
yield return new WaitForSeconds(1);
clock = false;
}
void UpdateTimer()
{
text.GetComponent<UnityEngine.UI.Text>().text = timeLeft.ToString();
}
}
Could someone help me to change the text format so it show things like real minutes and seconds? Thanks in advance! Btw someone said to me that i would need to use math to change the mins and secs variables, but i don’t know how to do it and in what it would help actually =\