diff --git a/Assets/Scripts/Logic/Data/World/Tower.cs b/Assets/Scripts/Logic/Data/World/Tower.cs index 617f5105afdf3cdc5f3f2ab3981f43da07ad8538..908a84f606227b870d5b4068924f38a54f18fb01 100644 --- a/Assets/Scripts/Logic/Data/World/Tower.cs +++ b/Assets/Scripts/Logic/Data/World/Tower.cs @@ -17,6 +17,7 @@ public class Tower : Building { float closestDistance = float.PositiveInfinity; Vector2 turretPosition = Position.ToVectorCentered(); foreach (Unit unit in World.Units) { + if (unit.Owner == Owner) continue; float distance = unit.Position.Distance2(turretPosition); if (closestDistance > distance) { closestDistance = distance; diff --git a/Assets/Scripts/Logic/Event/World/Barrack/IBarrackEvent.cs b/Assets/Scripts/Logic/Event/World/Barrack/IBarrackEvent.cs index 13843197dfd8660395af604688d19492f4bb8cf5..49b9eb38e8d93d9d988b4d673f55d56bebf72999 100644 --- a/Assets/Scripts/Logic/Event/World/Barrack/IBarrackEvent.cs +++ b/Assets/Scripts/Logic/Event/World/Barrack/IBarrackEvent.cs @@ -1,5 +1,3 @@ -using Logic.Data.World; - namespace Logic.Event.World.Barrack { public interface IBarrackEvent { public Data.World.Barrack Barrack { get; } diff --git a/Assets/Scripts/Presentation/World/Tower.cs b/Assets/Scripts/Presentation/World/Tower.cs index 43a8e382c24923e00a00a8674558da4fce103937..66eb4e6eb5f26fe79cdcb171d142f6dc8e52ef16 100644 --- a/Assets/Scripts/Presentation/World/Tower.cs +++ b/Assets/Scripts/Presentation/World/Tower.cs @@ -23,14 +23,9 @@ public class Tower : Structure { private World _world; private void FixedUpdate() { - Logic.Data.World.Unit logicTarget = _data.Target ?? _data.ClosestEnemy; - if (logicTarget != null && logicTarget.IsAlive) { - Vector3 target = _world.LogicToPresentation(logicTarget).transform.position; - Vector3 direction = (target - rotatingTurret.position).normalized; - float angle = Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x); - Quaternion desired = Quaternion.AngleAxis(angle - 90, Vector3.forward); - rotatingTurret.rotation = Quaternion.RotateTowards(rotatingTurret.rotation, desired, - Time.fixedDeltaTime * turretRotationSpeed); + if (_data.Type.Range > 0) { + Logic.Data.World.Unit logicTarget = _data.Target ?? _data.ClosestEnemy; + if (logicTarget != null) RotateTurret(logicTarget); } } @@ -56,5 +51,14 @@ public class Tower : Structure { public void DestroyTower() { Destroy(gameObject); } + + private void RotateTurret(Logic.Data.World.Unit logicTarget) { + Vector3 target = _world.LogicToPresentation(logicTarget).transform.position; + Vector3 direction = (target - rotatingTurret.position).normalized; + float angle = Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x); + Quaternion desired = Quaternion.AngleAxis(angle - 90, Vector3.forward); + rotatingTurret.rotation = Quaternion.RotateTowards(rotatingTurret.rotation, desired, + Time.fixedDeltaTime * turretRotationSpeed); + } } }