Finish work

This commit is contained in:
Michal Pikulski
2025-12-04 02:16:38 +01:00
parent 88049ac97c
commit 9b71b00441
17 changed files with 1684 additions and 127 deletions

View File

@@ -56,6 +56,13 @@ namespace Minigames.FortFight.Projectiles
public Vector2 LaunchDirection { get; protected set; }
public float LaunchForce { get; protected set; }
#endregion
#region Timeout
private const float ProjectileTimeout = 10f; // Destroy projectile after 10 seconds if stuck/off-map
private Coroutine timeoutCoroutine;
#endregion
#region Components
@@ -181,6 +188,41 @@ namespace Minigames.FortFight.Projectiles
// Fire event
OnLaunched?.Invoke(this);
// Start timeout - destroy projectile after configured time if it hasn't been destroyed
StartTimeoutTimer();
}
#endregion
#region Timeout
/// <summary>
/// Start timeout timer. Projectile will auto-destroy after timeout to prevent stuck/lost projectiles.
/// </summary>
private void StartTimeoutTimer()
{
if (timeoutCoroutine != null)
{
StopCoroutine(timeoutCoroutine);
}
timeoutCoroutine = StartCoroutine(TimeoutCoroutine());
}
/// <summary>
/// Timeout coroutine - destroys projectile after configured time
/// </summary>
private System.Collections.IEnumerator TimeoutCoroutine()
{
yield return new WaitForSeconds(ProjectileTimeout);
// Only destroy if still exists (might have been destroyed by collision already)
if (this != null && gameObject != null)
{
Logging.Debug($"[ProjectileBase] {gameObject.name} timed out after {ProjectileTimeout}s, destroying...");
DestroyProjectile();
}
}
#endregion
@@ -305,6 +347,13 @@ namespace Minigames.FortFight.Projectiles
{
Logging.Debug($"[ProjectileBase] Destroying {gameObject.name}");
// Stop timeout coroutine if running
if (timeoutCoroutine != null)
{
StopCoroutine(timeoutCoroutine);
timeoutCoroutine = null;
}
// Fire destroyed event
OnDestroyed?.Invoke(this);