towers fall from the sky - neat!

This commit is contained in:
Ian Woods 2026-07-03 14:05:08 -07:00
parent d14305d804
commit 362b76ae75
10 changed files with 396 additions and 219 deletions

View file

@ -58,6 +58,12 @@ namespace TD.Combat
// is in range, the tower fires and the timer resets to 1 / AttacksPerSecond.
private float attackCooldown;
// Counts down from towerInstance.LandingDuration, set in OnNetworkSpawn. Combat is
// fully inert until it reaches zero, so a tower can't target/fire while its mesh is
// still visually falling (TowerLandingVisual). Server-only; independent of whatever
// the client-side fall visual is doing to the (possibly shared, on a host) transform.
private float landingCooldown;
// Cached on OnNetworkSpawn — avoids GetComponent every Update.
private TowerInstance towerInstance;
@ -102,6 +108,7 @@ namespace TD.Combat
public override void OnNetworkSpawn()
{
towerInstance = GetComponent<TowerInstance>();
landingCooldown = towerInstance.LandingDuration;
replicatedTarget.OnValueChanged += HandleReplicatedTargetChanged;
// Late-joining clients receive the NV's current value in the initial
@ -128,6 +135,12 @@ namespace TD.Combat
{
if (!IsServer) return;
if (landingCooldown > 0f)
{
landingCooldown -= Time.deltaTime;
return;
}
TowerDefinition def = towerInstance?.Definition;
if (def == null || def.Range <= 0f || def.AttacksPerSecond <= 0f) return;