/// <summary> /// Called when a unit is to enter/attack this tower. /// See documenation for full explaination and metrics. /// If unit is friendly, stationed units is increased. /// Raises ChangedFaction and AttackedByUnit events. /// </summary> /// <param name="unit">Unit.</param> public void UnitEntered(UnitBehavior unit) { if (unit.Faction == Faction) { // Friendly units are transfered to this towers group unit.TransferGroup(stationedGroup); unit.gameObject.SetActive(false); } else { // Hostile units damage this towers stationed unit group int strength = FactionController.GetAttackStrengthForFaction(unit.Faction); stationedGroup.Damage(strength); // Change tower's faction if last unit was killed if (stationedGroup.Empty) { TowerController.ConvertTowerToFaction(this, unit.Faction); if (ChangedFaction != null) { ChangedFaction(Faction); SetGraphic(); } } unit.ImpactKill(); if (AttackedByUnit != null) { AttackedByUnit(unit); } } }