协同程序

using UnityEngine;
using System.Collections;


public class CorountineTest01 : MonoBehaviour {


// Use this for initialization
void Start () {
        // //Debug.Log("Test Start");
        yield return StartCoroutine(Test());
        // StartCoroutine(Test02(3));
        // //Debug.Log("Test End");
        //延迟3秒之后  执行方法Test03
        Invoke("Test03",3);




        InvokeRepeating("Test03", 0, 2);
    }
// Update is called once per frame
void Update () {

}
    IEnumerator Test02(int wave)
    {
        int count = 0;
        while (count<wave)
        {
            count++;
            yield return StartCoroutine(Test01(5));
            if (count==1)
            {
                StopAllCoroutines();//break
            }
            Debug.Log("第" + count + "波怪产生结束");
            yield return new WaitForSeconds(5);
            Debug.Log("注意,下一波即将产生");
        }
        Debug.Log("游戏结束");
    }


    void Test03()
    {
        Debug.Log("InvokeTest");
    }
    IEnumerator Test01(int number)
    {
        //yield return new WaitForSeconds(2);
        //Debug.Log("终于执行到了***");
        //yield return new WaitForSeconds(3);
        //Debug.Log("执行3秒");
        //yield return new WaitForSeconds(4);
        //Debug.Log("执行4秒");
        //yield return new WaitForSeconds(5);
        //Debug.Log("执行5秒");
        int count = 0;
        while (count<number)
        {
            count++;
            yield return new WaitForSeconds(1);
            Debug.Log("这是产生的第" + count + "个怪物");
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值