Infinite Coroutine

2 Questions.

  1. Am curious if the RegenerateStaminaRoutine() using a while(true) can cause problems with performance if it never returns. If it does not cause problems, then question 2
  2. Can an Infinite Coroutine like this be used for a Game Timer that returns the number of seconds elapsed since Game Started.

Is it a better practice to invoke the CoRoutine to run maxStamina times everytime Stamina is consumed and that too only if the same Coroutine is not already running ?

In this case it does not, because it’s much the same as a game loop (that runs and never returns) and it only executes every timeBetweenStaminaRegen seconds.

Time.time gives you the number of seconds that elapsed since the game has started, so you don’t need an infinite coroutine to do that.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms