Friday, 10 July 2015

countdown timer in unity c# mm:ss format

Create "GameObject ==> UI ==> Text".
Attach below script to Canvas

Code :-
=====

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class timerScript : MonoBehaviour {

public Text TimerText;
public float countdownTime = 60 ;
// Update is called once per frame
void Update () {
countdownTime -= Time.deltaTime;
int minutes = Mathf.FloorToInt(countdownTime / 60F);
int seconds = Mathf.FloorToInt(countdownTime - minutes * 60);
string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
TimerText.text = niceTime;
}
}



2 comments: