Unity塔防类游戏用协程实现产生怪的波数和个数

来源:互联网 发布:农业技术网络书屋 编辑:程序博客网 时间:2024/05/21 17:27
using UnityEngine;using System.Collections;public class EnemyNumHyp : MonoBehaviour{    public GameObject enemyPrefabHyp;    // Use this for initialization    void Start()    {        StartCoroutine(Test02(10));    }    // Update is called once per frame    void Update()    {    }    //num:一共产生多少波怪    IEnumerator Test02(int num)    {        int count = 0;        while (count < num)        {            count++;            yield return StartCoroutine(Test01(5));            Debug.Log("第" + count + "怪产生结束");            //每波怪产生的时间差            yield return new WaitForSeconds(15);            Debug.Log("注意第" + (count + 1) + "波怪即将产生");        }        Debug.Log("GameOver");    }    //number:每波怪的数量    IEnumerator Test01(int number)    {        int count = 0;        while (count < number)        {            count++;            //每个怪产生的时间差            yield return new WaitForSeconds(0.5f);            //这里克隆的位置信息是博主需要的位置,根据情况自己设定   Instantiate(enemyPrefabHyp, new Vector3(-48,0.5f,-70f), Quaternion.identity);        }    }}
阅读全文
0 0
原创粉丝点击