WolfHuntGameMode.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WolfHuntGameMode : ChallengeGameMode
  5. {
  6. public WolfHuntGameMode(GameMgr gameMgr) : base(gameMgr) {
  7. this.animalTypeID = 2;
  8. animalPrefab = animalsBaseT.Find("Wolf").gameObject;
  9. baseCreateDistance = 5;
  10. AddSelectLevelView();
  11. }
  12. //动物的创建列表(数组元素表示动物颜色样式)
  13. int[] animalCreateList;
  14. //动物创建列表的当前索引值
  15. int animalCreateIndex = 0;
  16. //设置关卡级别
  17. public override void SetLevel(int level) {
  18. if (level == 1) {
  19. animalCreateList = new int[]{1, 1};
  20. arrowCount = 5;
  21. time = 60;
  22. }
  23. else if (level == 2) {
  24. animalCreateList = new int[]{1, 1, 1, 1};
  25. arrowCount = 10;
  26. time = 70;
  27. }
  28. else if (level == 3) {
  29. animalCreateList = new int[]{2, 2};
  30. arrowCount = 8;
  31. time = 80;
  32. }
  33. else if (level == 4) {
  34. animalCreateList = new int[]{1, 1, 2, 2};
  35. arrowCount = 13;
  36. time = 90;
  37. }
  38. else if (level == 5) {
  39. animalCreateList = new int[]{1, 1, 1, 1, 2, 2, 2, 2};
  40. arrowCount = 26;
  41. time = 120;
  42. }
  43. if (animalCreateList != null) animalCount = animalCreateList.Length;
  44. CreateAnimal();
  45. }
  46. float baseCreateDistance = 0;
  47. float plusCreateDistance = 3;
  48. void CreateAnimal() {
  49. if (animalCreateIndex >= animalCreateList.Length) return;
  50. int animalStyleID = animalCreateList[animalCreateIndex++];
  51. //计算初始生成位置,后面的兔子生成越来越远,在标准方向的±30°内生成
  52. #region
  53. float createDistance = baseCreateDistance;
  54. baseCreateDistance += plusCreateDistance;
  55. Vector3 standardPointer = animalsBaseT.forward;
  56. Vector3 displace = standardPointer * createDistance;
  57. displace = Quaternion.AngleAxis(40 - Random.value * 80, Vector3.up) * displace;
  58. Vector3 newPos = animalsBaseT.position + displace;
  59. #endregion
  60. GameObject animalObject = GameObject.Instantiate(animalPrefab, newPos, Quaternion.identity, animalsBaseT);
  61. animalObject.SetActive(true);
  62. Wolf wolf = animalObject.GetComponent<Wolf>();
  63. wolf.baseDistance = createDistance;
  64. wolf.baseDistanceMoveRange = plusCreateDistance;
  65. wolf.hp = animalStyleID == 1 ? 5 : 8;
  66. wolf.ChangeColorByType(animalStyleID);
  67. wolf.RotateByWorldY(Random.value * 360);
  68. wolf.onDie += delegate(Wolf wf) {
  69. animalCount--;
  70. animalSet.Remove(wf);
  71. CreateAnimal();
  72. };
  73. animalSet.Add(wolf);
  74. if (animalSet.Count < maxAnimalCountAtTheSameTime) {
  75. CreateAnimal();
  76. }
  77. }
  78. }