Created
October 17, 2017 00:12
-
-
Save igolden/384d3983ded5715561c9ed0ae33def2c to your computer and use it in GitHub Desktop.
Timer for unity
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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class Timer : MonoBehaviour { | |
public Text timerLabel; | |
private float time; | |
void Update() | |
{ | |
time += Time.deltaTime; | |
var minutes = time / 60; //Divide the guiTime by sixty to get the minutes. | |
var seconds = time % 60;//Use the euclidean division for the seconds. | |
var fraction = (time * 100) % 100; | |
//update the label value | |
timerLabel.text = string.Format("{0:00} : {1:00} : {2:000}", minutes, seconds, fraction); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment