控制敌人数量及波数

来源:互联网 发布:淘宝韩妆正品店铺推荐 编辑:程序博客网 时间:2024/06/14 09:01
using UnityEngine;using System.Collections;public class CreateEnemeies : MonoBehaviour {    float timer = 0;    //    float timer2 = 0;    //产生敌人的速率    public float rate;    //敌人的预制体    public GameObject enemeyPrefab;    //每一波的时间    public float timesofEachWave = 30;    //每一波的已经产生的数量    public int count;    // Use this for initialization    void Start () {    }    // Update is called once per frame    void Update () {        timer2 += Time.deltaTime;        if (timer2 < timesofEachWave && count!=10)        {            timer += Time.deltaTime;            if (timer > rate)            {                Instantiate(enemeyPrefab, Vector3.zero, Quaternion.identity);                count++;                timer -= rate;            }        }        if (timer2>timesofEachWave)        {            timer2 -= timesofEachWave;            count = 0;        }    }}