A coroutine allows you to spread tasks across several frames. In Unity, a coroutine is a method that can pause execution and return control to Unity but then continue where it left off on the following frame.
I wrote some script to clone this.
I have some issues like : i want to create many coroutine easier, stop coroutine immediately.
may be can you complete it or any better idea!
sleep(seconds: number) {
return new Promise((resole) => setTimeout(resole, seconds * 1000));
}
async startCountDownAsync() {
await this.sleep(1);
this.startCountDown();
}
async startCountdown() {
this._isStartCountDown = false;
await this.sleep(1);
this.checkEndGame();
this._isStartCountDown = true;
}
update(dt){
if (this._isStartCountDown) {
this.startCountdown();
}
}

