33 lines
964 B
C#
33 lines
964 B
C#
using BaseGames.Combat;
|
||
using UnityEngine;
|
||
|
||
namespace BaseGames.Enemies
|
||
{
|
||
/// <summary>
|
||
/// 接触伤害:组件启用时持续激活 HitBox,令敌人对接触到的目标定期造成伤害。
|
||
/// 适用于无攻击动画的简单障碍物、环境危险或测试场景。
|
||
/// </summary>
|
||
[RequireComponent(typeof(HitBox))]
|
||
public class BodyContactDamage : MonoBehaviour
|
||
{
|
||
[SerializeField] private float _repeatInterval = 0.5f;
|
||
|
||
private HitBox _hitBox;
|
||
private float _timer;
|
||
|
||
private void Awake() => _hitBox = GetComponent<HitBox>();
|
||
private void OnEnable() { _hitBox?.Activate(); _timer = 0f; }
|
||
private void OnDisable() => _hitBox?.Deactivate();
|
||
|
||
private void Update()
|
||
{
|
||
_timer += Time.deltaTime;
|
||
if (_timer >= _repeatInterval)
|
||
{
|
||
_timer = 0f;
|
||
_hitBox.Activate();
|
||
}
|
||
}
|
||
}
|
||
}
|