unity3d 调用函数与协程的区别和适用范围
—恢复内容开始—
1 using UnityEngine; 2 using System.Collections; 3 4 5 public class 调用函数与协程 : MonoBehaviour { 6 7 8 // Use this for initialization 9 void Start () { 10 //查看协程将调用函数注释,查看调用函数将协程注释 11 12 13 #region 协程 14 print("开始一个程序"); 15 StartCoroutine("xiecheng"); 16 print("结束一个程序"); 17 #endregion 18 19 20 #region 调用函数 21 //5秒后调用 22 //Invoke("invoke",1f);//不重复 一秒后调用 23 //InvokeRepeating("diaoyonghanshu", 2f, 0.5f);//两秒后调用函数并间隔0.5秒重复调用 24 #endregion 25 } 26 27 // Update is called once per frame 28 void Update () { 29 30 } 31 32 33 #region 协程函数 34 IEnumerator xiecheng() 35 { 36 //等待一秒 37 yield return new WaitForSeconds(1f); 38 print("开启另一个程序"); 39 yield return new WaitForSeconds(2f); 40 print("等了两秒开启另一个程序"); 41 } 42 #endregion 43 44 45 #region 调用函数 46 //void invoke() 47 //{ 48 // print("1s后调用 调用函数 不重复!"); 49 //} 50 //void diaoyonghanshu() 51 //{ 52 // print("每隔一定时间调用 调用函数 重复!"); 53 //} 54 #endregion 55 }