RabbitHuntGameMode.cs 3.3 KB

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