Friday, July 10, 2015

countdown timer in unity c# mm:ss format

iklan
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;
}
}



countdown timer in unity c# mm:ss format
4/ 5
Oleh