Greetings,
I am looking for a pausing solution.
The issue is that my game has a double score power-up for 10 seconds:
private bool isDoubleScoreActive;
private int runningDoubleScoreCoroutinesCount;
EventManager.TriggerEvent("DoubleScore"); // triggers the event
private void OnDoubleScore(object sender, object parameters)
{
StartCoroutine(DoubleScore()); // starts the coroutine
}
private IEnumerator DoubleScore()
{
if (!isDoubleScoreActive)
{
doubleScoreIndicator.SetActive(true);
isDoubleScoreActive = true; // any score added gets doubled
}
runningDoubleScoreCoroutinesCount += 1; // used to track if we have active coroutines so we can extend the length of the power-up
yield return new WaitForSeconds(10); // the power-up lasts for 10 sec
runningDoubleScoreCoroutinesCount -= 1; // the coroutine is done
if (runningDoubleScoreCoroutinesCount == 0) // if this is the only coroutine, the power-up has ended
{
doubleScoreIndicator.SetActive(false);
isDoubleScoreActive = false;
}
}
And this kind of pattern makes it impossible to pause the game, anyone has any idea how to solve this?
The only idea I have is to make a function update time each frame and stop changing time when paused is set to true. Are there any better solutions?
Thanks for your time