Files
zeling_v2/Assets/_Game/Scripts/Enemies/BodyContactDamage.cs
Joywayer cc046c53b3 fix(combat): HitBox 命中节奏统一 + 投射物穿透可配
HitBox 新增 HitMode Single/Interval:Interval 用 Enter/Exit 跟踪占用 + Update 轮询,对停留目标按间隔重判,不再依赖 OnTriggerEnter 单次语义。BodyContactDamage 改用 Interval 模式,修复停留在接触判定内、无敌结束后不再受伤的 bug;FlyingEnemy 接触伤害加按目标间隔节流。ProjectileConfigSO 新增 MaxHits 默认 1 即命中即消失,Projectile 按命中预算回收,修掉默认无限穿透;弹反守卫避免反射后立即回收。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 16:31:55 +08:00

30 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BaseGames.Combat;
using UnityEngine;
namespace BaseGames.Enemies
{
/// <summary>
/// 接触伤害:组件启用时把 HitBox 切到 Interval 模式并持续激活,
/// 令敌人对停留在判定盒内的目标按固定间隔重复造成伤害。
/// 适用于无攻击动画的简单障碍物、环境危险或测试场景。
///
/// 重复命中由 HitBox 的 Interval 节奏Enter/Exit 跟踪占用 + Update 轮询)驱动,
/// 不再依赖反复 Activate()——后者无法对已停留目标补发 OnTriggerEnter会导致只命中一次。
/// </summary>
[RequireComponent(typeof(HitBox))]
public class BodyContactDamage : MonoBehaviour
{
[SerializeField] private float _repeatInterval = 0.5f;
private HitBox _hitBox;
private void Awake() => _hitBox = GetComponent<HitBox>();
private void OnEnable()
{
_hitBox?.SetIntervalMode(_repeatInterval);
_hitBox?.Activate();
}
private void OnDisable() => _hitBox?.Deactivate();
}
}