IEnumerator DecreaseTime ()
{
while (timeLeft >= 0.0f) {
while (isPaused) {
yield return new WaitForEndOfFrame ();
}
timeLeft = timeLeft - 0.01f;
Debug.Log (timeLeft);
yield return new WaitForSeconds (0.01f);
}
}
The timeLeft variables value is 10 at the startOfCoroutine but than i want to decrease the timeLeft with 100th part of second because this time is used for progress bar and that way i can make it look smooth.But this coroutine doesn’t run for 10 seconds it runs for something like 22.6 seconds.
A coroutine can only run at max with the current frame rate. WaitForSeconds will wait the at least the specified time but the coroutine can only be resumed once each frame. “0.01” would require at least a framerate of 100 fps.