协程是Unity在同步线程中,开启一个协程函数,这个协程函数中设置一个条件(yield return+条件),程序中每一帧进行监测,当不满足该条件后,先return出去执行其他的;直到检测到条件满足时,执行协程函数中yield return...后续逻辑。
例如:
{
Debug.Log("one second before execute");
yield return new WaitForSeconds(1);
Debug.Log("one second after execute");
}
使用StartCoroutine(WaitForOneSecond());开启一个协程函数WaitForOneSecondCoroutine;
首先执行Debug.Log("one second before execut