Skip to content

Instantly share code, notes, and snippets.

@Venkat-Swaraj
Created August 25, 2023 06:01
Show Gist options
  • Save Venkat-Swaraj/cf55aba854735ea623e090c3716fe2dd to your computer and use it in GitHub Desktop.
Save Venkat-Swaraj/cf55aba854735ea623e090c3716fe2dd to your computer and use it in GitHub Desktop.
Countdown timer using Coroutine in Unity
private float currCountdownValue = 0;
public IEnumerator StartCountdown(float countdownValue = 10) {
currCountdownValue = countdownValue;
while (currCountdownValue > 0) {
Debug.Log("Countdown: " + currCountdownValue);
yield return new WaitForSeconds(1.0f);
currCountdownValue--;
}
}
// to use
StartCoroutine(StartCountdown());
// or
StartCoroutine(StartCountdown(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment