void UpDateSelectShip() { if (GetShip()) { FightShip selectShip = GetShip(); Image image = selectShip.transform.GetComponent <Image>(); image.color = Color.red; } }
public void ShortRangeAttack(FightShip ship) { ship.defence = ship.defence - attack; if (ship.defence < 0) { ship.defence = 0; ship.Die(); } ship.slider.value = ship.defence; }
public int CompareTo(FightShip other) { //等于返回0 int re = other.speed.CompareTo(speed); if (0 == re) { //id相同再比较Name return(camp.CompareTo(other.camp)); } return(re); }
FightShip GetShip() { Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(inputRay, out hit)) { FightShip selectShip = hit.transform.GetComponent <FightShip>(); return(selectShip); } else { return(null); } }
public IEnumerator Fire(int attackTurn, FightShip beFiredShip) { if (!beFiredShip.dead) { switch (attackTurn) { case (1): RemoteAttack(beFiredShip); break; case (2): MediumRangeAttack(beFiredShip); break; case (3): ShortRangeAttack(beFiredShip); break; } attacked = true; yield return(new WaitForSeconds(1 / 2f)); image.color = Color.white; } }
void LoadFleet(int attackerIndex, int defenderIndex, MapGlobal MapGlobal) { this.attackerIndex = attackerIndex; this.defenderIndex = defenderIndex; for (int i = 0; i < MapGlobal.Fleets.Length; i++) { if (MapGlobal.Fleets[i].mapIndex == attackerIndex) { MapGlobal.Fleet attacker = MapGlobal.Fleets[i]; for (int j = 0; j < attacker.MapShip.Length; j++) { FightShip ship = Instantiate(shipPrefabs[attacker.MapShip[j].shipTypeIndex]); ship.attack = attacker.MapShip[j].attack; ship.defence = attacker.MapShip[j].defence; ship.MaxDefence = attacker.MapShip[j].maxDefence; ship.speed = attacker.MapShip[j].speed; ship.camp = attacker.camp; ship.shipTypeIndex = attacker.MapShip[j].shipTypeIndex; //text.text = ship.hullNumber; //image = ship.headPortrait; if (ship.camp == 0 || ship.camp == 2) { weFleet.Add(ship); } else if (ship.camp == 1) { enemyFleet.Add(ship); } fightFleet.Add(ship); ship.transform.SetParent(weContent, false); } } else if (MapGlobal.Fleets[i].mapIndex == defenderIndex) { MapGlobal.Fleet defender = MapGlobal.Fleets[i]; for (int j = 0; j < defender.MapShip.Length; j++) { FightShip ship = Instantiate(shipPrefabs[defender.MapShip[j].shipTypeIndex]); ship.attack = defender.MapShip[j].attack; ship.defence = defender.MapShip[j].defence; ship.MaxDefence = defender.MapShip[j].maxDefence; ship.speed = defender.MapShip[j].speed; ship.camp = defender.camp; ship.shipTypeIndex = defender.MapShip[j].shipTypeIndex; //text.text = ship.hullNumber; //image = ship.headPortrait; if (ship.camp == 0 && ship.camp == 2) { weFleet.Add(ship); } else if (ship.camp == 1) { enemyFleet.Add(ship); } fightFleet.Add(ship); ship.transform.SetParent(enemyContent, false); } } } fightFleet.Sort((x, y) => x.CompareTo(y)); }