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 = 8; BanBowReady(); } public override void Start() { UnbanBowReady(); if (nextLevel != null) { SetLevel(int.Parse(nextLevel)); AddHuntGameView(); } else { AddSelectLevelView(); } } //动物的创建列表(数组元素表示动物颜色样式) int[] animalCreateList; //动物创建列表的当前索引值 int animalCreateIndex = 0; //设置关卡级别 public override void SetLevel(int level) { currentlevel = level; if (level == 1) { animalCreateList = new int[]{1, 1}; arrowCountMax = arrowCount = 4; } else if (level == 2) { animalCreateList = new int[]{2, 2}; arrowCountMax = arrowCount = 8; } else if (level == 3) { animalCreateList = new int[]{3, 3}; arrowCountMax = arrowCount = 12; } else if (level == 4) { animalCreateList = new int[]{1, 1, 2, 2}; arrowCountMax = arrowCount = 12; } else if (level == 5) { animalCreateList = new int[]{1, 1, 1, 3, 3, 3}; arrowCountMax = arrowCount = 24; } if (animalCreateList != null) animalCountMax = animalCount = animalCreateList.Length; time = arrowCountMax * 10; CreateAnimal(); } float baseCreateDistance = 0; float plusCreateDistance = 2.5f; public bool banCreateAnimal = false; void CreateAnimal() { if (banCreateAnimal) return; 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(Random.Range(-14f, 14f), 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.uid = animalCreateIndex; 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(); } } }