Files
AppleHillsProduction/Assets/Scripts/Minigames/DivingForPictures/Obstacles/ObstacleCollision.cs

62 lines
2.2 KiB
C#
Raw Normal View History

using UnityEngine;
namespace Minigames.DivingForPictures
{
/// <summary>
/// Collision behavior that handles damage from mobile obstacles.
/// Uses trigger-based collision detection with shared immunity state.
/// </summary>
public class ObstacleCollision : PlayerCollisionBehavior
{
2025-09-24 13:31:15 +02:00
protected override void OnEnable()
{
base.OnEnable();
// Subscribe to immunity events
OnImmunityStarted += HandleImmunityStarted;
OnImmunityEnded += HandleImmunityEnded;
}
protected override void OnDisable()
{
// Unsubscribe from immunity events
OnImmunityStarted -= HandleImmunityStarted;
OnImmunityEnded -= HandleImmunityEnded;
base.OnDisable();
}
protected override void HandleCollisionResponse(Collider2D obstacle)
{
// Mark the obstacle as having dealt damage to prevent multiple hits
FloatingObstacle obstacleComponent = obstacle.GetComponent<FloatingObstacle>();
if (obstacleComponent != null)
{
obstacleComponent.MarkDamageDealt();
}
Debug.Log($"[ObstacleCollision] Player hit by obstacle {obstacle.gameObject.name}");
}
/// <summary>
2025-09-24 13:31:15 +02:00
/// Handler for immunity started event - replaces OnImmunityStart method
/// </summary>
2025-09-24 13:31:15 +02:00
private void HandleImmunityStarted()
{
2025-09-24 13:31:15 +02:00
Debug.Log($"[ObstacleCollision] Damage immunity started for {_gameSettings.EndlessDescenderDamageImmunityDuration} seconds");
// Don't block input for obstacle damage - let player keep moving
// The shared immunity system will handle the collision prevention
}
/// <summary>
2025-09-24 13:31:15 +02:00
/// Handler for immunity ended event - replaces OnImmunityEnd method
/// </summary>
2025-09-24 13:31:15 +02:00
private void HandleImmunityEnded()
{
Debug.Log($"[ObstacleCollision] Damage immunity ended");
// No special handling needed - shared immunity system handles collider re-enabling
}
}
}