Files
AppleHillsProduction/Assets/Scripts/Minigames/DivingForPictures/PlayerDamageCollisionBehavior.cs

103 lines
3.8 KiB
C#
Raw Normal View History

2025-09-17 16:10:18 +02:00
using UnityEngine;
namespace Minigames.DivingForPictures
{
/// <summary>
/// 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).
/// </summary>
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<FloatingObstacle>();
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}");
}
/// <summary>
/// Applies damage to the player
/// Override this method to integrate with your health/damage system
/// </summary>
/// <param name="damage">Amount of damage to apply</param>
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);
}
/// <summary>
/// Override to prevent input blocking during damage immunity
/// Since obstacles pass through the player, we don't want to block input
/// </summary>
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();
}
/// <summary>
/// Override to handle immunity end without input restoration
/// </summary>
protected override void OnImmunityEnd()
{
Debug.Log($"[PlayerDamageCollisionBehavior] Damage immunity ended");
// Broadcast damage end event
TriggerDamageEnd();
}
/// <summary>
/// Public method to set base damage at runtime
/// </summary>
public void SetBaseDamage(float damage)
{
baseDamage = damage;
}
/// <summary>
/// Public method to toggle between base damage and obstacle-specific damage
/// </summary>
public void SetUseObstacleDamage(bool useObstacleDamage)
{
useObstacleDamageValue = useObstacleDamage;
}
}
}