I am making a timer where they have a certain amount of time to beat a level, and I want it to display milliseconds as well. How do I do that?
public float timeLeft = 15f;
public GameObject player;
public GameObject environment;
[Header("UI Components")]
public Text timer;
public GameObject timerText;
public GameObject healthText;
public GameObject shieldText;
public GameObject livesText;
public GameObject skipsText;
public GameObject pointsText;
public GameObject respawnScreen;
private bool dead;
private void Update()
{
timeLeft -= Time.deltaTime;
UpdateLevelTimer(timeLeft);
if (timeLeft <= 0)
Die();
}
private void UpdateLevelTimer(float totalSeconds)
{
int minutes = Mathf.FloorToInt(totalSeconds / 60f);
int seconds = Mathf.RoundToInt(totalSeconds % 60);
float milliseconds = Mathf.FloorToInt(totalSeconds * 1000);
string formatedSeconds = seconds.ToString();
if (seconds == 60)
{
seconds = 0;
minutes += 1;
}
timer.text = minutes.ToString("00") + ":" + seconds.ToString("00") + "." + milliseconds.ToString("00");
timeLeft = Mathf.Clamp(timeLeft, 0, 12000000);
}
private void Die()
{
dead = true;
timerText.SetActive(false);
healthText.SetActive(false);
shieldText.SetActive(false);
livesText.SetActive(false);
skipsText.SetActive(false);
pointsText.SetActive(false);
respawnScreen.SetActive(true);
environment.SetActive(false);
Destroy(player);
print("Player has died.");
}