| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class WolfHuntGameMode : ChallengeGameMode
- {
- public WolfHuntGameMode(GameMgr gameMgr) : base(gameMgr) {
- this.animalTypeID = 2;
- animalPrefab = animalsBaseT.Find("Wolf").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;
- time = 60;
- }
- else if (level == 2) {
- animalCreateList = new int[]{1, 1, 1, 1};
- arrowCount = 10;
- time = 70;
- }
- else if (level == 3) {
- animalCreateList = new int[]{2, 2};
- arrowCount = 8;
- time = 80;
- }
- else if (level == 4) {
- animalCreateList = new int[]{1, 1, 2, 2};
- arrowCount = 13;
- time = 90;
- }
- else if (level == 5) {
- animalCreateList = new int[]{1, 1, 1, 1, 2, 2, 2, 2};
- arrowCount = 26;
- time = 120;
- }
- 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(40 - Random.value * 80, Vector3.up) * displace;
- Vector3 newPos = animalsBaseT.position + displace;
- #endregion
- GameObject animalObject = GameObject.Instantiate(animalPrefab, newPos, Quaternion.identity, animalsBaseT);
- animalObject.SetActive(true);
- Wolf wolf = animalObject.GetComponent<Wolf>();
- wolf.baseDistance = createDistance;
- wolf.baseDistanceMoveRange = plusCreateDistance;
- wolf.hp = animalStyleID == 1 ? 5 : 8;
- wolf.ChangeColorByType(animalStyleID);
- wolf.RotateByWorldY(Random.value * 360);
- wolf.onDie += delegate(Wolf wf) {
- animalCount--;
- animalSet.Remove(wf);
- CreateAnimal();
- };
- animalSet.Add(wolf);
- if (animalSet.Count < maxAnimalCountAtTheSameTime) {
- CreateAnimal();
- }
- }
- }
|