public void changeRound() { StopAllCoroutines(); StartCoroutine("Secs"); timer = -1; if (round_counter != 2) { round_counter++; } else { round_counter = 0; } if (round[round_counter] == battleRound.Opponent_1 && opponents[0].GetComponent <Enemy_script>().isAlive()) { current_round = battleRound.Opponent_1; currentOpponentID = 0; setTurnSign(0); round_text.GetComponent <Text_animation>().startAnim(_enemyManagerScript.enemies[battles[battle_id].opponent_ids[0]].enemy_name, 0.05f); _notification.message(_enemyManagerScript.enemies[battles[battle_id].opponent_ids[0]].enemy_name + "'s round!", 3); _isOpponentAttacked = false; StartCoroutine("enemyopponentAttack", 0); } else if (round[round_counter] == battleRound.Opponent_1 && !opponents[0].GetComponent <Enemy_script>().isAlive()) { changeRound(); } else if (round[round_counter] == battleRound.Opponent_2 && opponents[1].GetComponent <Enemy_script>().isAlive()) { current_round = battleRound.Opponent_2; currentOpponentID = 1; setTurnSign(1); round_text.GetComponent <Text_animation>().startAnim(_enemyManagerScript.enemies[battles[battle_id].opponent_ids[1]].enemy_name, 0.05f); _notification.message(_enemyManagerScript.enemies[battles[battle_id].opponent_ids[1]].enemy_name + "'s round!", 3); _isOpponentAttacked = false; StartCoroutine("enemyopponentAttack", 1); } else if (round[round_counter] == battleRound.Opponent_2 && !opponents[1].GetComponent <Enemy_script>().isAlive()) { changeRound(); } else if (round[round_counter] == battleRound.Player) { current_round = battleRound.Player; setTurnSign(2); round_text.GetComponent <Text_animation>().startAnim(_characterStats.Player_name, 0.05f); _notification.message(_characterStats.Player_name + "'s round!", 3); } if (!opponents[0].GetComponent <Enemy_script>().isAlive() && !opponents[1].GetComponent <Enemy_script>().isAlive()) { isOngoing = false; showResults("Victory"); } spellbarController(); }
IEnumerator fight(GameObject player0, GameObject enemy) { playerpro playerbp = player0.GetComponent <playerpro>(); enemypro enemybp = enemy.GetComponent <enemypro>(); GameObject labels = GameObject.Find("UI Root").transform.Find("main").Find("battlePanel").gameObject; while (playerbp.hp > 0 && enemybp.hp > 0) { //玩家出手回合 if (thisRound == battleRound.player) { enemybp.hp -= battleSinglehit(playerbp.atk, enemybp.def); if (enemybp.hp < 0) { enemybp.hp = 0; } labels.transform.Find("enemy_hp").GetComponent <UILabel>().text = enemybp.hp.ToString(); thisRound = battleRound.enemy; } else if (thisRound == battleRound.enemy) { playerbp.hp -= battleSinglehit(enemybp.atk, playerbp.def); if (playerbp.hp < 0) { playerbp.hp = 0; } labels.transform.Find("hero_hp").GetComponent <UILabel>().text = playerbp.hp.ToString(); thisRound = battleRound.player; } yield return(new WaitForSeconds(0.4f)); } if (playerbp.hp <= 0) { Debug.Log("玩家死亡"); } else if (enemybp.hp <= 0) { Debug.Log("怪物死亡");//玩家面板更新血量,钱币,经验 Destroy(enemy.gameObject); GameObject.Find("battle0" + player.playerInfloor.ToString() + "(Clone)").GetComponent <myTweenAlpha>()._thisSprite.Remove(enemy.gameObject); GameObject.Find("UI Root").transform.Find("main").Find("labelPanel").Find("hp").GetComponent <UILabel>().text = playerbp.hp.ToString(); player.empiric += enemybp.deadEmpiric;//更新后台数据 player.HP = playerbp.hp; GameObject.Find("UI Root").transform.Find("main").Find("labelPanel").Find("jy").GetComponent <UILabel>().text = player.empiric.ToString(); player.coin += enemybp.deadCoin;//更新后台数据 GameObject.Find("UI Root").transform.Find("main").Find("labelPanel").Find("coin").GetComponent <UILabel>().text = player.coin.ToString(); //更新后台当前层缓存 floor_01 f1 = GameObject.Find("battle0" + player.playerInfloor.ToString() + "(Clone)").GetComponent <floor_01>(); int[] enemypos = f1.transMaptoArray(enemy.transform.position); for (int i = 0; i <= f1.enemylist.Count - 1; i++) { if (f1.CompareArray(enemypos, f1.enemylist[i].zuobiao)) { f1.enemylist.RemoveAt(i); } } GameObject.Find("Main Camera").GetComponent <gameData>().floorDataList[player.playerInfloor - 1].enemylist = f1.enemylist;//将层数据同步到后台 //弹出战斗奖励 GameObject info = (GameObject)Instantiate(Resources.Load("Prefabs/UIPanel")); info.transform.parent = GameObject.Find("UI Root").transform.Find("main").transform; info.transform.localScale = new Vector3(1f, 1f, 1f); //info.transform.FindChild("labelc_Coin").GetComponent<UILabel>().text = ""; //info.transform.FindChild("labelc_em").GetComponent<UILabel>().text = ""; //info.transform.FindChild("Label").GetComponent<UILabel>().text = ""; //info.transform.FindChild("Label 1").GetComponent<UILabel>().text = ""; //info.transform.FindChild("Label 2").GetComponent<UILabel>().text = ""; //info.transform.FindChild("Label 3").GetComponent<UILabel>().text = ""; info.transform.Find("labelc_Coin").GetComponent <UILabel>().text = enemybp.deadCoin.ToString(); info.transform.Find("labelc_em").GetComponent <UILabel>().text = enemybp.deadEmpiric.ToString(); Destroy(info, 0.7f); } thisRound = battleRound.player; labels.SetActive(false); //战斗结束关闭面板 labels.transform.Find("enemysprite").GetComponent <UISprite>().spriteName = ""; //清空sprite Destroy(labels.transform.Find("enemysprite").gameObject.GetComponent <UISpriteAnimation>()); //删除动画组件 //等待1秒后,再开启移动 //yield return new WaitForSeconds(1f); //gameObject.GetComponent<controller>().isBattle = false;//开启移动标示 StopCoroutine("fight"); }