Created
June 21, 2020 20:45
-
-
Save saturngamesss/a3398fd5d6aeacfb4a1564e2295e05fe to your computer and use it in GitHub Desktop.
Basic timer for Unity Engine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//************** 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