Unity3D总结记录(七) Unity中延时和协程处理

Unity C#脚本编写过程中,如遇到需要延迟执行的程序可使用如下语句:

yield return new WaitForSeconds(waitTime);

具体使用方法如下:

using System.Collections;
using System.Collections.Generic;

using UnityEngine;

void Start(){

  StartCoroutine(waitTime(8));  //协程程序与普通函数使用方法一样

}


  //在类中新建IEnumerator函数,并在该函数中使用延迟语句及延迟执行语句。在其他函数中用StartCoroutin()方法直接调用即可。

IEnumerator waitTime(float x) 

    {
        Debug.Log("Wait time Start");
        yield return new WaitForSeconds(x);  //延迟语句
        Debug.Log("Wait time End");
        proMessage_1.GetComponent<Text>().enabled = false;

    }



猜你喜欢

转载自blog.csdn.net/weixin_39591280/article/details/80798570