using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class RabbitHuntGameMode : ChallengeGameMode { public RabbitHuntGameMode(GameMgr gameMgr) : base(gameMgr) { this.animalTypeID = 0; animalPrefab = animalsBaseT.Find("Rabbit").gameObject; baseCreateDistance = 5; AddSelectLevelView(); } //动物的创建列表(数组元素表示动物颜色样式) int[] animalCreateList; //动物创建列表的当前索引值 int animalCreateIndex = 0; //设置关卡级别 public override void SetLevel(int level) { if (level == 1) { animalCreateList = new int[]{1, 1}; arrowCount = 5; } else if (level == 2) { animalCreateList = new int[]{2, 2}; arrowCount = 6; } else if (level == 3) { animalCreateList = new int[]{3, 3}; arrowCount = 7; } else if (level == 4) { animalCreateList = new int[]{1, 1, 2, 2}; arrowCount = 8; } else if (level == 5) { animalCreateList = new int[]{1, 1, 1, 3, 3, 3}; arrowCount = 10; } if (animalCreateList != null) animalCount = animalCreateList.Length; CreateAnimal(); } float baseCreateDistance = 0; float plusCreateDistance = 3; void CreateAnimal() { if (animalCreateIndex >= animalCreateList.Length) return; int animalStyleID = animalCreateList[animalCreateIndex++]; //计算初始生成位置,后面的兔子生成越来越远,在标准方向的±30°内生成 #region float createDistance = baseCreateDistance; baseCreateDistance += plusCreateDistance; Vector3 standardPointer = animalsBaseT.forward; Vector3 displace = standardPointer * createDistance; displace = Quaternion.AngleAxis(30 - Random.value * 60, Vector3.up) * displace; Vector3 newPos = animalsBaseT.position + displace; #endregion GameObject animalObject = GameObject.Instantiate(animalPrefab, newPos, Quaternion.identity, animalsBaseT); animalObject.SetActive(true); Rabbit rabbit = animalObject.GetComponent(); rabbit.baseDistance = createDistance; rabbit.baseDistanceMoveRange = plusCreateDistance; rabbit.hp = animalStyleID; rabbit.ChangeColorByType(animalStyleID); rabbit.RotateByWorldY(Random.value * 360); rabbit.onDie += delegate(Rabbit rb) { animalCount--; animalSet.Remove(rb); CreateAnimal(); }; animalSet.Add(rabbit); if (animalSet.Count < maxAnimalCountAtTheSameTime) { CreateAnimal(); } } }