1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemyManage : MonoBehaviour
- {
- /// <summary>
- /// 生成的物体
- /// </summary>
- public GameObject[] enemys;
- /// <summary>
- /// 生成的数量
- /// </summary>
- public int count;
- /// <summary>
- /// 开始等待的时间
- /// </summary>
- public float startWait;
- /// <summary>
- /// 结束等待的时间
- /// </summary>
- public float overWait;
- /// <summary>
- /// 生成等待时间
- /// </summary>
- public float buildWait;
- /// <summary>
- /// 生成的点
- /// </summary>
- 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); //等待下一次生成
- }
- }
- }
|