Skip to content

Instantly share code, notes, and snippets.

@igolden
Created October 17, 2017 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igolden/384d3983ded5715561c9ed0ae33def2c to your computer and use it in GitHub Desktop.
Save igolden/384d3983ded5715561c9ed0ae33def2c to your computer and use it in GitHub Desktop.
Timer for unity
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