using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //难度控制类,用于改变刷新的怪物的战斗力数值 //该类为刷兵关卡设计的基类 public class DiffultyController : MonoBehaviour { [Range (1,3)] public int diffcultyLevel; //波次数 [Range(1, 30)] public int turn_; //剩余波次 private int remainTurn; //每波数量 [Range(5,40)] public int Number_; //每波剩余数量 private int remainNumber; // //关卡配置(根据关卡对波次数量刷兵进行配置) public int stageNum; public StageAdapter_1 stage; public StageAdapter_1[] allstage; //显示相关 public Text remainTurnTxt; public Text remainNumberTxt; public Text stageTxt; //敌人生成相关 //生成类型 public GameObject enemy_1; public GameObject enemy_2; public GameObject enemy_3; public GameObject enemy_4; public GameObject enemy_5; public GameObject enemy_6; //生成的数组(所有需要生成的敌人) public GameObject[] enemyAll_; //所有生成的boss(基本上关底出现,一个到两个左右) public GameObject[] bossAll_; //生成地点 public List birthPoint_1; public MenuController_2 menu; //生成怪物特效 public GameObject birthParticle; //玩家相关 public GameObject player; // Use this for initialization void Start () { stageNum = 0; } // Update is called once per frame void Update () { } //简单模式 public void EasyMode() { diffculityChange_Hp(1); StartCoroutine(StageAction(stage)); } //一般难度模式 public void NormalMode() { diffculityChange_Hp(2); StartCoroutine(StageAction(stage)); } //困难模式 public void DiffcultMode() { diffculityChange_Hp(3); StartCoroutine(StageAction(stage)); } //关卡之间的切换与继续游戏 public void nextStage() { if (allstage[stageNum]) { int stageNum_Next = stageNum + 1; stageTxt.text = "下一关准备(第"+ stageNum_Next + "关)"; stage = allstage[stageNum]; } else { //游戏结束,至此全部通关 } } public void gameContinue() { StartCoroutine(StageAction(stage)); } //实现批次进行进攻 IEnumerator EasyAction() { while (remainTurn > 0) { for (int i = 0; i < Number_; i++) { GameObject enemy_ = Instantiate(enemy_1); GameObject birthParticle_1 = Instantiate(birthParticle); enemy_.SetActive(true); int pos = i % 3; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0,Random.Range(0,360f),0); yield return new WaitForSeconds(0.16f); } remainTurn -= 1; yield return new WaitForSeconds(40f); } } //关卡适配后的刷兵方案 IEnumerator StageAction(StageAdapter_1 stage) { //关闭菜单 menu.closeAllMenu(); //初始化玩家 player.GetComponent().enabled = true; player.GetComponent().enabled = true; player.GetComponent().rightPointer.SetActive(false); player.GetComponent().leftPointer.SetActive(false); player.GetComponent().Weapon_.SetActive(true); //敌人1生成数量 int enemy_1_Count = Random.Range(stage.enemy_1_Count_min, stage.enemy_1_Count_max); int enemy_2_Count = Random.Range(stage.enemy_2_Count_min, stage.enemy_2_Count_max); int enemy_3_Count = Random.Range(stage.enemy_3_Count_min, stage.enemy_3_Count_max); int enemy_4_Count = Random.Range(stage.enemy_4_Count_min, stage.enemy_4_Count_max); int enemy_5_Count = stage.lastWaveEnemy_5_Count; int last_Count = stage.allEnemyCount - enemy_1_Count - enemy_2_Count - enemy_3_Count - enemy_4_Count; remainTurn = stage.allEnemyWave; remainTurnTxt.text = remainTurn + " / " + stage.allEnemyWave; while (remainTurn > 0) { for (int i = 0; i < enemy_1_Count; i++) { GameObject enemy_ = Instantiate(enemy_1); enemy_.SetActive(true); enemy_.GetComponent().deathEvent.AddListener(reduceEnemyCount); int pos = i % 3; GameObject birthParticle_1 = Instantiate(birthParticle); birthParticle_1.transform.position = birthPoint_1[pos].position; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360f), 0); produceEnmeyCount(1); remainNumberTxt.text = remainNumber + ""; yield return new WaitForSeconds(0.16f); } for (int i = 0; i < enemy_2_Count; i++) { GameObject enemy_ = Instantiate(enemy_2); enemy_.SetActive(true); enemy_.GetComponent().deathEvent.AddListener(reduceEnemyCount); int pos = i % 3; GameObject birthParticle_1 = Instantiate(birthParticle); birthParticle_1.transform.position = birthPoint_1[pos].position; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360f), 0); produceEnmeyCount(1); remainNumberTxt.text = remainNumber + ""; yield return new WaitForSeconds(0.16f); } for (int i = 0; i < enemy_3_Count; i++) { GameObject enemy_ = Instantiate(enemy_3); enemy_.SetActive(true); enemy_.GetComponent().deathEvent.AddListener(reduceEnemyCount); int pos = i % 3; GameObject birthParticle_1 = Instantiate(birthParticle); birthParticle_1.transform.position = birthPoint_1[pos].position; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360f), 0); produceEnmeyCount(1); remainNumberTxt.text = remainNumber + ""; yield return new WaitForSeconds(0.16f); } for (int i = 0; i < enemy_4_Count; i++) { GameObject enemy_ = Instantiate(enemy_4); enemy_.SetActive(true); enemy_.GetComponent().deathEvent.AddListener(reduceEnemyCount); int pos = i % 3; GameObject birthParticle_1 = Instantiate(birthParticle); birthParticle_1.transform.position = birthPoint_1[pos].position; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360f), 0); produceEnmeyCount(1); remainNumberTxt.text = remainNumber + ""; yield return new WaitForSeconds(0.16f); } for (int i = 0; i < last_Count; i++) { GameObject enemy_ = Instantiate(enemyAll_[stage.remainEnemyType]); enemy_.SetActive(true); enemy_.GetComponent().deathEvent.AddListener(reduceEnemyCount); int pos = i % 3; GameObject birthParticle_1 = Instantiate(birthParticle); birthParticle_1.transform.position = birthPoint_1[pos].position; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360f), 0); produceEnmeyCount(1); remainNumberTxt.text = remainNumber + ""; yield return new WaitForSeconds(0.16f); } remainTurn -= 1; remainTurnTxt.text = remainTurn + " / " + stage.allEnemyWave; if (remainTurn == 1) { //最后一波大怪刷新 for (int i = 0; i < enemy_5_Count; i++) { GameObject enemy_ = Instantiate(enemy_5); enemy_.SetActive(true); enemy_.GetComponent().deathEvent.AddListener(reduceEnemyCount); int pos = i % 3; GameObject birthParticle_1 = Instantiate(birthParticle); birthParticle_1.transform.position = birthPoint_1[pos].position; enemy_.transform.position = birthPoint_1[pos].position; enemy_.transform.localEulerAngles = new Vector3(0, Random.Range(0, 360f), 0); produceEnmeyCount(1); remainNumberTxt.text = remainNumber + ""; yield return new WaitForSeconds(0.16f); } } if (remainTurn <= 0) { break; } yield return new WaitForSeconds(stage.nextWaveSecond); } //等待怪物数量减少 print("endBirth"); while (remainNumber>0) { yield return new WaitForEndOfFrame(); } yield return new WaitForSeconds(10f); stageNum++; print("endEnemy"); //开启下一关菜单 //返回菜单玩家 player.GetComponent().enabled = false; //player.GetComponent().enabled = false; player.GetComponent().rightPointer.SetActive(true); player.GetComponent().leftPointer.SetActive(true); player.GetComponent().Weapon_.SetActive(false); if (stageNum<=10) { nextStage(); menu.openMenu(6); } VoiceController_ Vcontroller_1 = GameObject.FindGameObjectWithTag("audioController").GetComponent(); Vcontroller_1.StopAllAudio(); yield return null; } //敌人数量减少 public void reduceEnemyCount() { remainNumber = remainNumber - 1; remainNumberTxt.text = remainNumber+""; } public void produceEnmeyCount(int count) { remainNumber = remainNumber + count; remainNumberTxt.text = remainNumber + ""; } //get public int getRemainTurn() { return remainTurn; } public int getRemainNumber() { return remainNumber; } //难度控制 public void diffculityChange_Hp(int HpPercent) { enemy_1.GetComponent().hp *= HpPercent; enemy_2.GetComponent().hp *= HpPercent; enemy_3.GetComponent().hp *= HpPercent; enemy_4.GetComponent().hp *= HpPercent; enemy_5.GetComponent().hp *= HpPercent; } }