Working collisions on event-based triggers
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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
|
||||
{
|
||||
[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 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;
|
||||
|
||||
// Mark the obstacle as having dealt damage to prevent multiple hits
|
||||
obstacleComponent.MarkDamageDealt();
|
||||
}
|
||||
}
|
||||
|
||||
// Apply damage (this could be extended to integrate with a health system)
|
||||
ApplyDamage(damageAmount);
|
||||
|
||||
Debug.Log($"[ObstacleCollision] 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($"[ObstacleCollision] 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($"[ObstacleCollision] Damage immunity started for {damageImmunityDuration} seconds");
|
||||
|
||||
// Don't block input for obstacle damage - let player keep moving
|
||||
// The shared immunity system will handle the collision prevention
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override to handle immunity end
|
||||
/// </summary>
|
||||
protected override void OnImmunityEnd()
|
||||
{
|
||||
Debug.Log($"[ObstacleCollision] Damage immunity ended");
|
||||
// No special handling needed - shared immunity system handles collider re-enabling
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user