Guides
Log In

Coroutine

A coroutine is a non-preemptive multitasking program component that works by pausing execution and then continuing where it left off. It is mainly used to execute such features such asynchronous operations, exceptions, event loops, iterators, infinite lists, and pipes.

Click here to learn more about Unityโ€™s coroutine.

๐Ÿ“˜

Coroutine

https://docs.unity3d.com/kr/current/Manual/Coroutines.html


ZEPETOScript implementation of Unity coroutines as follows.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { WaitForSeconds } from 'UnityEngine';

export default class Coroutine extends ZepetoScriptBehaviour {
    
    private current: number;
    
    Start() {
        this.current = 0;
        console.log(`start routine`);
        this.StartCoroutine(this.DoRoutine());
    }

    *DoRoutine() {
        while(true) {
            yield null;
            console.log(`[${this.current++}] Wait to next routine..`);
            yield new WaitForSeconds(1);
        }
    }
}

Check out the test code output screen below.

1119