- Home /
Skip function
I'm using a IEnumerator
with yield return new WaitForSeconds (wait);
between spawning waves of enemies. I want to create a button so if the players want the next wave to come more quickly he just presses it, stops yield return new WaitForSeconds (wait);
, and the code after it is executed. How can this be implemented?
Comment
Best Answer
Answer by Jessespike · Jul 12, 2016 at 05:39 PM
One solution may be to replace WaitForSeconds for WaitForEndOfFrame in a loop.
//yield return new WaitForSeconds (wait)
while (elapsedTime < wait) {
yield return new WaitForEndOfFrame();
elapsedTime += Time.deltaTime;
}
To skip you can assign elapsedTime to wait or add a bool to the loop condition:
while (elapsedTime < wait && skipping == false) {
yield return new WaitForEndOfFrame();
elapsedTime += Time.deltaTime;
}