Skip to content

Instantly share code, notes, and snippets.

@saturngamesss
Created June 21, 2020 20:45
Show Gist options
  • Save saturngamesss/a3398fd5d6aeacfb4a1564e2295e05fe to your computer and use it in GitHub Desktop.
Save saturngamesss/a3398fd5d6aeacfb4a1564e2295e05fe to your computer and use it in GitHub Desktop.
Basic timer for Unity Engine.
//************** REAL GAMES STUDIO ***************
//************************************************
//realgamesss.weebly.com
//gamejolt.com/@Real_Game
//realgamesss.newgrounds.com/
//real-games.itch.io/
//youtube.com/channel/UC_Adg-mo-IPg6uLacuQCZCQ
//************************************************
using UnityEngine;
using TMPro;
public class Timer : MonoBehaviour
{
public TextMeshProUGUI timer;
void Update()
{
timer.text = FormatTime(Time.time);
}
string FormatTime(float time)
{
int intTime = (int)time;
int minutes = intTime / 60;
int seconds = intTime % 60;
float fraction = time * 1000;
fraction = (fraction % 1000);
string timeText = string.Format("{0:00}:{1:00}:{2:000}", minutes, seconds, fraction);
return timeText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment