协程脚本:
using System.Collections;
using UnityEngine;
public class MyTest : MonoBehaviour
{
// 声明一个协程
Coroutine coroutine;
void Start()
{
// 定义协程
coroutine = StartCoroutine(MyCoroutine());
// 停止协程
StopCoroutine(coroutine);
}
// 运行的协程程序
IEnumerator MyCoroutine()
{
yield return new WaitForSeconds(0.1f);
for (int i = 0; i < 100; i++)
{
Debug.Log(i);
}
}
}