public int timeLeft = 5;
public Text countdownText;
// Use this for initialization
void Start()
{
StartCoroutine("LoseTime");
}
// Update is called once per frame
void Update()
{
countdownText.text = ("" + timeLeft);
if (timeLeft <= 0)
{
StopCoroutine("");
countdownText.text = "";
}
}
IEnumerator LoseTime()
{
while (true)
{
yield return new WaitForSeconds(1);
timeLeft--;
}
}
private int _timeLeft = 5;
public Text countdownText;
private float _currentTime;
void Start()
{
_currentTime = _timeLeft;
}
void Update()
{
_currentTime -= Time.deltaTime;
countdownText.text = (int)_currentTime.ToString());
if(_currentTime <= 0)
{
Debug.Log("StartGame");
}
}
public class DelayedStart: MonoBehaviour
{
public int count = 5;
public static bool IsStarted = false;
void Awake()
{
StartCoroutine(StartCounting());
}
private IEnumerator StartCounting()
{
for (int i = count; i > 0; i--)
{
yield return new WaitForSeconds(1f);
Debug.LogFormat("Time Left: {0} s", i);
}
IsStarted = true;
}
}