Skip to content

Instantly share code, notes, and snippets.

@smkplus
Created August 19, 2018 06:44
Show Gist options
  • Save smkplus/4eba51bea3607dd305afa3075cdfba54 to your computer and use it in GitHub Desktop.
Save smkplus/4eba51bea3607dd305afa3075cdfba54 to your computer and use it in GitHub Desktop.
CountDown Unity.md
````
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