Created
August 25, 2023 06:01
-
-
Save Venkat-Swaraj/cf55aba854735ea623e090c3716fe2dd to your computer and use it in GitHub Desktop.
Countdown timer using Coroutine in Unity
This file contains 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
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