EnemyManage.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EnemyManage : MonoBehaviour
  5. {
  6. /// <summary>
  7. /// 生成的物体
  8. /// </summary>
  9. public GameObject[] enemys;
  10. /// <summary>
  11. /// 生成的数量
  12. /// </summary>
  13. public int count;
  14. /// <summary>
  15. /// 开始等待的时间
  16. /// </summary>
  17. public float startWait;
  18. /// <summary>
  19. /// 结束等待的时间
  20. /// </summary>
  21. public float overWait;
  22. /// <summary>
  23. /// 生成等待时间
  24. /// </summary>
  25. public float buildWait;
  26. /// <summary>
  27. /// 生成的点
  28. /// </summary>
  29. public Transform[] points;
  30. // Use this for initialization
  31. void Start()
  32. {
  33. StartCoroutine(Create());
  34. }
  35. // Update is called once per frame
  36. void Update()
  37. {
  38. }
  39. IEnumerator Create()
  40. {
  41. yield return new WaitForSeconds(startWait); //开始等待
  42. while (true)
  43. {
  44. for (int i = 0; i < count; i++)
  45. {
  46. GameObject obj = enemys[Random.Range(0, enemys.Length)]; //随机生成一个敌人
  47. Transform newPos = points[Random.Range(0, points.Length)]; //随机生成一个位置
  48. Instantiate(obj, newPos.position, newPos.rotation); //开始生成
  49. yield return new WaitForSeconds(buildWait); //生成等待
  50. }
  51. yield return new WaitForSeconds(overWait); //等待下一次生成
  52. }
  53. }
  54. }