using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyManage : MonoBehaviour { /// /// 生成的物体 /// public GameObject[] enemys; /// /// 生成的数量 /// public int count; /// /// 开始等待的时间 /// public float startWait; /// /// 结束等待的时间 /// public float overWait; /// /// 生成等待时间 /// public float buildWait; /// /// 生成的点 /// public Transform[] points; // Use this for initialization void Start() { StartCoroutine(Create()); } // Update is called once per frame void Update() { } IEnumerator Create() { yield return new WaitForSeconds(startWait); //开始等待 while (true) { for (int i = 0; i < count; i++) { GameObject obj = enemys[Random.Range(0, enemys.Length)]; //随机生成一个敌人 Transform newPos = points[Random.Range(0, points.Length)]; //随机生成一个位置 Instantiate(obj, newPos.position, newPos.rotation); //开始生成 yield return new WaitForSeconds(buildWait); //生成等待 } yield return new WaitForSeconds(overWait); //等待下一次生成 } } }