// Remove a soldier from the selected country - setup phase only public void Remove() { if (phases.setupPhase) { click.Play(); country = GameObject.FindGameObjectWithTag("SelectedCountry"); // Creates a list of the country's soldiers soldiers = new List <GameObject> (); if (teamChecker.UnderControl(country) & deploySoldiers.CanRemoveSoldier()) { foreach (Transform child in country.transform) { if (child.name == "Soldier(Clone)") { soldiers.Add(child.gameObject); } } // Find and delete the last soldier in the list if (soldiers.Count > 1) { soldierToDelete = soldiers [soldiers.Count - 1]; if (soldierToDelete.tag == "DeployedSoldier") { DestroyImmediate(soldierToDelete); UpdateNumbers(country, -1); troopCount.UpdateTroopBankV2(playerTurn.CurrentPlayer(), -1); } } } buttonColour.SetupPlusMinusColour(); } }
// moves a soldier fromCountry to toCountry - called by fwd and back buttons public void MoveSoldier(GameObject fromCountry, GameObject toCountry) { // create a list of the fromCountry's soldiers soldiers = new List <GameObject> (); foreach (Transform soldier in fromCountry.transform) { if (soldier.name == "Soldier(Clone)") { soldiers.Add(soldier.gameObject); } } // remove the last soldier fromCountry soldierToTransfer = soldiers [soldiers.Count - 1]; GameObject.DestroyImmediate(soldierToTransfer); // add a soldier toCountry addSoldier = toCountry.GetComponent <AddSoldier> (); addSoldier.PlaceSoldier(); // update game stats troopCount.UpdateTroopBankV2(playerTurn.CurrentPlayer(), -1); countryManagement.ChangeArmySize(fromCountry, -1); countryManagement.ChangeArmySize(toCountry, 1); buttonColour.MovementPlusMinusColour(fromCountry, toCountry); }
// Places a soldier at the country's adjusted COM public void PlaceSoldier() { soldierPosition = new Vector3(0, 0, 0); soldierPosition = PositionAdjustment(findCOM(this.transform)); // Instantiates a soldier at the stored placer location clone = Instantiate(Resources.Load("Soldier"), soldierPosition, Quaternion.identity) as GameObject; clone.transform.parent = this.transform; if (phases.setupPhase) { clone.gameObject.tag = "DeployedSoldier"; } // requires player index as unput, hence the -1 soldierManagement.SetSoldierColour(clone, playerTurn.CurrentPlayer() - 1); // update game stats troopCount.UpdateTroopBankV2(playerTurn.CurrentPlayer(), 1); }