I have a Coroutine (X) that waits for seconds before it does something. However, during that time there is another Coroutine that may trigger (Y), and during the time it's on X has to pause waiting for seconds, until Y finishes its job. The point is not to waste the wait time of X.
Pausing the game is not possible since everything else has to work during that time.
I tried to add the bool isLightningAbilityRunning
that checks if Y is running, but since X is not repeating itself and just waiting, it doesn't get to that point.
The whole X coroutine:
private IEnumerator TriggerGravityAbility() {
var gravityDuration = gravityInitialDuration + UpgradeManager.instance.GravityDurationUpgrade();
AudioManager.instance.PlayGravitySound();
CubeSpawner.instance.gameObject.SetActive(false); // Stop spawning cubes
Physics2D.gravity = new Vector2(0f, 1f);
ParticleModifier.instance.SetGravity(0f);
CubeBehavior.instance.border.isTrigger = false;
CubeBehavior.instance.ignoreBorderLightning = true;
while (isLightningAbilityRunning) {
yield return null;
}
yield return new WaitForSeconds(gravityDuration);
CubeBehavior.instance.DestroyOutOfCameraCubes();
CubeSpawner.instance.gameObject.SetActive(true); // Start spawning cubes
Physics2D.gravity = new Vector2(0f, -9.81f);
ParticleModifier.instance.ResetGravity();
CubeBehavior.instance.border.isTrigger = true;
CubeBehavior.instance.ignoreBorderLightning = false;
}
How can I make this work?