StartCoroutine

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
    void Start()
    {
        print("Starting" + Time.time);

        StartCoroutine(WaitAndPrint(2.0f));

        print("Before WaitAndPrint Finishes " + Time.time);
    }

    private IEnumerator WaitAndPrint(float waitTime)
    {
        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint 1 " + Time.time);

        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint 2 " + Time.time);

        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint 3 " + Time.time);

        yield return new WaitForSeconds(waitTime);
        print("WaitAndPrint 4 " + Time.time);
    }
}



无知什么的,最让我恼火了.之前理解协程有误,在这里重新说一下.协程并不是线程,而是开始之后,在固定的时机由引擎调用,调用的时机由yield return的是什么有关.看这张图吧,昨天偶遇的.

StartCoroutine_第1张图片

图片出处:点击打开链接

你可能感兴趣的:(Class,float)