RabbitHuntGameMode.cs 3.3 KB

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