• unity3d之 C# WaitFOrSeconds()


    学习unity3d不久。在使用WaitFOrSeconds()时,遇到了不少麻烦,故记录,以警示后人。

    首先介绍C#和javascript 在使用它有非常大的差别。

    javascript能够直接使用 yield WaitFOrSeconds(5);即延时5秒

    而C#中,首先定义自己的方法

    IEnumerator MyMethod() {
     Debug.Log("Before Waiting 2 seconds");
     yield return new WaitForSeconds(2);
     Debug.Log("After Waiting 2 Seconds");
    }
    然后利用协程调用

    StartCoroutine(MyMethod());或
    StartCoroutine(“MyMethod”);
    在这里要注意。要想2秒之后。运行还有一个函数,如Application.LoadLevel(0);须要把它放进协程里

    IEnumerator MyMethod() {
     Debug.Log("Before Waiting 2 seconds");
     yield return new WaitForSeconds(2);
     Debug.Log("After Waiting 2 Seconds");
    Application.LoadLevel(0);
    }
    之后在调用MyMethod()会实现等2秒后。再运行loadlevel()
    因为对协程,还不太了解。我会之后补充这方面知识。

  • 相关阅读:
    luogu 1726 上白泽惠音
    POJ1419 Graph Coloring(最大独立集)(最大团)
    POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
    POJ 1966 Cable TV Network(顶点连通度的求解)
    POJ 1523 SPF(寻找关节点)
    Dwarves (有向图判环)
    POJ 3041 Asteroids(最小点覆盖集)
    POJ 1043 What's In A Name?(唯一的最大匹配方法)
    POJ Girls and Boys (最大独立点集)
    Jewelry Exhibition(最小点覆盖集)
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10736443.html
  • Copyright © 2020-2023  润新知