IEnumerator SelectTarget(Ship _ship, bool isComputerShip, bool isReselect) { print("selecting target for" + _ship + " " + isComputerShip); if (!isComputerShip) { if (isReselect) { text.text = _ship.name + "'s target died reselect your target"; } else if (_ship is SupportClass) { text.text = "which target would you like: " + _ship.name + " to heal?"; } else { text.text = "which target would you like: " + _ship.name + " to attack?"; } } computerFleet = computer.hangar.GetFleet(); playerFleet = playerHangar.GetFleet(); //target selection List <GameObject> attacking = new List <GameObject>(); List <GameObject> aliveTargets = new List <GameObject>(); List <GameObject> defending = new List <GameObject>(); List <GameObject> aliveAllies = new List <GameObject>(); if (isComputerShip) { attacking = checkAttack(playerFleet); defending = checkDefence(playerFleet); aliveTargets = playerHangar.GetFleetList(); aliveAllies = computer.hangar.GetFleetList(); } else { attacking = checkAttack(computerFleet); defending = checkDefence(computerFleet); aliveTargets = computer.hangar.GetFleetList(); aliveAllies = playerHangar.GetFleetList(); } if (_ship is SwarmClass || _ship is StealthClass) { _ship.AddTargets(aliveTargets); } else if (_ship.state == Ship.State.heal) { _ship.AddTargets(aliveAllies); } else if (!isComputerShip) { if (defending.Count >= 1) { _ship.AddTargets(defending); } else { _ship.AddTargets(attacking); } } //get list of possible targets for the ship to select a target for List <Ship> shipTargets = new List <Ship>(); foreach (KeyValuePair <string, GameObject> element in _ship.GetTargets()) { shipTargets.Add(element.Value.GetComponent <Ship>()); } if (_ship is SwarmClass) { List <string> t = new List <string>(); foreach (Ship s in shipTargets) { print("selecting all targets for swarmclass"); t.Add(s.name); } _ship.SelectTargets(t); } else { //random computer selection if (isComputerShip) { computer.targetSelection(_ship, playerHangar.GetShipList()); } //the logic for activating and deactivating the buttons for each targetable ship else { foreach (Ship s in shipTargets) { //activate the button for each targetable ship s.activateButton(); s.setButtonText(s.name); s.onTargetPress.AddListener(_ship.OnTargetSelectionCallback); } } while (_ship.GetSelectedTargets().Count < 1) { yield return(null); } foreach (Ship s in shipTargets) { //deactivate the button for each ship s.deactivateButton(); s.onTargetPress.RemoveAllListeners(); } } yield return(new WaitForSeconds(1)); text.text = string.Empty; }