using UnityEngine; namespace Minigames.DivingForPictures { /// /// Collision behavior that handles damage from mobile obstacles. /// Unlike bump collisions, this only deals damage without physical response. /// Detects collisions between Player layer (7) and QuarryObstacle layer (11). /// public class PlayerDamageCollisionBehavior : PlayerCollisionBehavior { [Header("Damage Settings")] [Tooltip("Base damage amount dealt by obstacles")] [SerializeField] private float baseDamage = 1f; [Tooltip("Whether to use the obstacle's individual damage value or the base damage")] [SerializeField] private bool useObstacleDamageValue = true; protected override void Awake() { base.Awake(); // Override the obstacle layer mask to target QuarryObstacle layer (11) obstacleLayerMask = 1 << 11; // QuarryObstacle layer } protected override void HandleCollisionResponse(Collider2D obstacle) { float damageAmount = baseDamage; // Try to get damage from the obstacle component if enabled if (useObstacleDamageValue) { FloatingObstacle obstacleComponent = obstacle.GetComponent(); if (obstacleComponent != null) { damageAmount = obstacleComponent.Damage; } } // Apply damage (this could be extended to integrate with a health system) ApplyDamage(damageAmount); Debug.Log($"[PlayerDamageCollisionBehavior] Player took {damageAmount} damage from obstacle {obstacle.gameObject.name}"); } /// /// Applies damage to the player /// Override this method to integrate with your health/damage system /// /// Amount of damage to apply protected virtual void ApplyDamage(float damage) { // For now, just log the damage // In a full implementation, this would reduce player health, trigger UI updates, etc. Debug.Log($"[PlayerDamageCollisionBehavior] Applied {damage} damage to player"); // TODO: Integrate with health system when available // Example: playerHealth.TakeDamage(damage); } /// /// Override to prevent input blocking during damage immunity /// Since obstacles pass through the player, we don't want to block input /// protected override void OnImmunityStart() { Debug.Log($"[PlayerDamageCollisionBehavior] Damage immunity started for {damageImmunityDuration} seconds"); // Don't block input for obstacle damage - let player keep moving // Only broadcast the damage event TriggerDamageStart(); } /// /// Override to handle immunity end without input restoration /// protected override void OnImmunityEnd() { Debug.Log($"[PlayerDamageCollisionBehavior] Damage immunity ended"); // Broadcast damage end event TriggerDamageEnd(); } /// /// Public method to set base damage at runtime /// public void SetBaseDamage(float damage) { baseDamage = damage; } /// /// Public method to toggle between base damage and obstacle-specific damage /// public void SetUseObstacleDamage(bool useObstacleDamage) { useObstacleDamageValue = useObstacleDamage; } } }