创造你的世界
脚本编写

协程

1min
协程是一个非抢占式的多任务程序组件,通过暂停执行然后继续从中断的地方继续工作。它主要用于执行异步操作、异常、事件循环、迭代器、无限列表和管道等功能。 点击这里了解更多关于unity的协程。 📘 协程 https //docs unity3d com/kr/current/manual/coroutines html https //docs unity3d com/kr/current/manual/coroutines html zepetoscript实现unity协程如下。 import { zepetoscriptbehaviour } from 'zepeto script'; import { waitforseconds } from 'unityengine'; export default class coroutine extends zepetoscriptbehaviour { private current number; start() { this current = 0; console log(`开始例程`); this startcoroutine(this doroutine()); } doroutine() { while(true) { yield null; console log(`\[${this current++}] 等待下一个例程 `); yield new waitforseconds(1); } } } 请查看下面的测试代码输出屏幕。