Unity: How To Make a UI Timer [Beginners Guide] + C# Script

Started by
0 comments, last by ThisIsFix 5 years ago

YouTube Video Tutorialhttps://www.youtube.com/watch?v=GPwp0Bd7WnA&feature=youtu.be

 

C# Script:


using UnityEngine;
using UnityEngine.UI;

public class UITimer : MonoBehaviour
{	
 public Text TimerText; 
 public bool playing;
 private float Timer;

 void Update () {

 	if(playing == true){
  
	  Timer += Time.deltaTime;
	  int minutes = Mathf.FloorToInt(Timer / 60F);
	  int seconds = Mathf.FloorToInt(Timer % 60F);
	  int milliseconds = Mathf.FloorToInt((Timer * 100F) % 100F);
	  TimerText.text = minutes.ToString ("00") + ":" + seconds.ToString ("00") + ":" + milliseconds.ToString("00");
	}

  }

}

Script Link: https://github.com/ThisIsFix/Unity-UI-Timer

This topic is closed to new replies.

Advertisement