Jump to content
  • Advertisement

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

Recommended Posts

Posted (edited)

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

Edited by ThisIsFix

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!