71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using Core;
|
|
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
|
|
{
|
|
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)
|
|
{
|
|
// Check if the obstacle is on the ObstacleLayer
|
|
if (obstacle.gameObject.layer != _devSettings.ObstacleLayer)
|
|
{
|
|
// If not on the obstacle layer, don't process the collision
|
|
Logging.Debug($"[ObstacleCollision] Ignored collision with object on layer {obstacle.gameObject.layer} (expected {_devSettings.ObstacleLayer})");
|
|
return;
|
|
}
|
|
|
|
// Mark the obstacle as having dealt damage to prevent multiple hits
|
|
FloatingObstacle obstacleComponent = obstacle.GetComponent<FloatingObstacle>();
|
|
if (obstacleComponent != null)
|
|
{
|
|
obstacleComponent.MarkDamageDealt();
|
|
}
|
|
|
|
Logging.Debug($"[ObstacleCollision] Player hit by obstacle {obstacle.gameObject.name}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for immunity started event - replaces OnImmunityStart method
|
|
/// </summary>
|
|
private void HandleImmunityStarted()
|
|
{
|
|
Logging.Debug($"[ObstacleCollision] Damage immunity started for {_gameSettings.DamageImmunityDuration} seconds");
|
|
|
|
// Don't block input for obstacle damage - let player keep moving
|
|
// The shared immunity system will handle the collision prevention
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for immunity ended event - replaces OnImmunityEnd method
|
|
/// </summary>
|
|
private void HandleImmunityEnded()
|
|
{
|
|
Logging.Debug($"[ObstacleCollision] Damage immunity ended");
|
|
// No special handling needed - shared immunity system handles collider re-enabling
|
|
}
|
|
}
|
|
}
|