Created
August 19, 2018 06:44
-
-
Save smkplus/4eba51bea3607dd305afa3075cdfba54 to your computer and use it in GitHub Desktop.
CountDown Unity.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```` | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class CountDown : MonoBehaviour { | |
public Text timerText; | |
public int timer; | |
void Start () | |
{ | |
StartCoroutine(Timer()); | |
Time.timeScale = 10; | |
} | |
IEnumerator Timer(){ | |
while(timer > 0){ | |
timer--; | |
int minutes = Mathf.FloorToInt(timer / 60F); | |
int seconds = Mathf.FloorToInt(timer - minutes * 60); | |
string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds); | |
timerText.text = niceTime; | |
yield return new WaitForSeconds(1); | |
} | |
} | |
} | |
```` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment