Hello everyone,
In my endless racer game there is continuously points adding while game in progress. After 20 seconds point starting to multiply by 2, then after 50 seconds multiply by 3, then after 90 seconds multiply by 4 and later by 5. And Points should only add while game in progress. I have script ready for everything but I don’t know how to pause this coroutine while game is not in progress and resume later when game resumes. Here is current script:
IEnumerator PointMultiplier()
{
while(true)
{
yield return new WaitForSeconds(0.1f);
if(GameManager.Instance.Status == GameStatus.GameInProgress)
{
yield return new WaitUntil(() => LevelManager.gameStarted);
yield return new WaitForSeconds(20f);
pointMultipier = 2;
multiplier.text = "X" + pointMultipier.ToString();
multiplier.GetComponent<Animation>().Play();
// StartCoroutine(MultiplierLerp());
yield return new WaitForSeconds(50f);
pointMultipier = 3;
multiplier.text = "X" + pointMultipier.ToString();
multiplier.GetComponent<Animation>().Play();
yield return new WaitForSeconds(90f);
pointMultipier = 4;
multiplier.text = "X" + pointMultipier.ToString();
multiplier.GetComponent<Animation>().Play();
yield return new WaitForSeconds(130f);
pointMultipier = 5;
multiplier.text = "X" + pointMultipier.ToString();
multiplier.GetComponent<Animation>().Play();
}
}
}
Can someone please modify and complete my script?
Thanks.
Thanks but it’s not just about pause. I am already using Time.timeScale while pause. Game character have 3 lives. When it die once game still running and on first tap character respawn. So between character death and respawn this coroutine should pause.
Of you want more fine-grained control than what you can get with timescale, you’ll need to keep your own timer variable instead of depending on WaitForSeconds.
True… but you could implement your own that waits until either or both conditions are true.
OP, if you make a separate little coroutine that loops until a timer counts up to your wait time, AND the condition is true, you can yield return that coroutine and things won’t move forward until both of those conditions are true.
Or you could just wait the time, THEN wait the condition, unless you intend the condition should shortcut the time.