// Update is called once per frame void Update() { if (checkUnits && unitsFalling == 0) //If we need to check the units and all of said units have finished falling (Brennan) { for (int i = unitList.Count - 1; i > -1; --i) //You have to move backwards through a list if you remove from it while iterating through it (Brennan) { if (unitList[i] != null) { if (unitList[i].tag == "Infantry") //If it's an Infantry we get the Infantry script { if (unitList[i].GetComponent <Infantry>().dead) { //Unit tR = unitList[i].GetComponent<Unit>(); //ScoreMaster.UpdateScore(tR); //DeleteUnitFromPlay(tR); //Destroy(unitList[i]); //unitList.Remove(unitList[i]); PlayerMaster.KillUnit(unitList[i].GetComponent <Unit>()); } } else { if (unitList[i].GetComponent <Cavalry>().dead) { /* Unit tR = unitList[i].GetComponent<Unit>(); * ScoreMaster.UpdateScore(tR); * DeleteUnitFromPlay(tR); * Destroy(unitList[i]); * unitList.Remove(unitList[i]);*/ PlayerMaster.KillUnit(unitList[i].GetComponent <Unit>()); } } } } for (int i = 0; i < unitList.Count; ++i) { if (unitList[i] != null) { unitList[i].transform.position = unitList[i].GetComponent <Unit>().CurrentHex.SpawnVector; unitList[i].transform.rotation = unitList[i].GetComponent <Unit>().URotation(); unitList[i].GetComponent <Rigidbody>().velocity = Vector3.zero; unitList[i].GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } } unitList.Clear(); checkUnits = false; } }
static IEnumerator Fight() //Handles and manages the FightScene { gP = GamePhase.Attack; while (AttackMaster.CombatCount != 0) { float rotation; if (PlayerMaster.CurrentTurn == 0) { rotation = 180; } else { rotation = 0; } instance.StartCoroutine(TopDownCamera.LerpToPosition(AttackMaster.CenterOfCombat(), Quaternion.Euler(90, rotation, 0))); yield return(new WaitForSeconds(2.0f)); //Wait to give the player a chance to see stuff instance.StartCoroutine(UIMaster.MoveCurtains(true)); //lower curtains yield return(null); //Wait at least one frame so that UIMaster.MovingCurtians can change value while (UIMaster.MovingCurtains) { yield return(null); } List <Unit> currentCombat = AttackMaster.CurrentCombatArea; List <Unit> toKill = AttackMaster.FightResults(); FightSceneMaster.SetUpFight(currentCombat, toKill); //Prepare the fightscene yield return(new WaitForSeconds(1.0f)); //Pause for dramatic effect instance.StartCoroutine(UIMaster.MoveCurtains(false)); //Raise Curtains yield return(null); while (UIMaster.MovingCurtains) { yield return(null); } SoundMaster.AttackCharge(); instance.StartCoroutine(FightSceneMaster.ToBattle()); //Begins FightScene yield return(null); //Wait at least one frame so that FightSceneMaster.Fighting can change value while (FightSceneMaster.Fighting) { yield return(null); } //SoundMaster.AttackResolution(); instance.StartCoroutine(UIMaster.MoveCurtains(true)); //Lower curtains again yield return(null); //Wait at least one frame so that UIMaster.MovingCurtians can change value while (UIMaster.MovingCurtains) { yield return(null); } FightSceneMaster.CleanUp(); //Resets FightScene yield return(new WaitForSeconds(0.25f)); //Pause instance.StartCoroutine(UIMaster.MoveCurtains(false)); //Raise curtains yield return(new WaitForFixedUpdate()); //Wait at least one frame so that UIMaster.MovingCurtians can change value while (UIMaster.MovingCurtains) { yield return(null); } yield return(new WaitForSeconds(1.0f)); foreach (Unit u in toKill) { PlayerMaster.KillUnit(u); //Kills dead units } yield return(new WaitForSeconds(1.0f)); //Pause to see aftermath } //return to player's position after the fight instance.StartCoroutine(TopDownCamera.LerpToPosition(PlayerMaster.CurrentPlayer.CameraPosistion, PlayerMaster.CurrentPlayer.CameraRotation)); DeactivateCannonByMove(PlayerMaster.OtherPlayer); if (PlayerMaster.CurrentTurn == 0) { HighlightMaster.HighlightMovable(PlayerMaster.OtherPlayer); } UIMaster.DisplayScore(); // WinByMove(); UIMaster.SetActionPanel(true); //Turns action pannel back on UIMaster.FadePhanel((int)UIPannels.Action); CannonMaster.CheckCannonCapture(); gP = GamePhase.Move; yield return(ChangeTurn()); acceptInput = true; }
public static void ResolveFight() { int p1 = 0; int p2 = 0; if (instance.combatAreas.Count != 0) { foreach (Unit u in instance.combatAreas[0]) { if (u.Player == 0) { p1++; } else { p2++; } HighlightMaster.HighlightUnitToggle(true, u); } } if (p1 == p2) { foreach (Unit u in instance.combatAreas[0]) { if (u != null) { PlayerMaster.KillUnit(u); } } } else { if (p1 > p2) { p1 = p2; } else { p2 = p1; } foreach (Unit u in instance.combatAreas[0]) { if (u != null) { if (u.Player == 0 && p1 != 0) { PlayerMaster.KillUnit(u); p1--; } else if (u.Player == 1 && p2 != 0) { PlayerMaster.KillUnit(u); p2--; } } } } foreach (Unit u in instance.combatAreas[0]) { if (u != null) { HighlightMaster.HighlightUnitToggle(false, u); } } instance.combatAreas.Remove(instance.combatAreas[0]); instance.combatCount--; }