Files
zeling_v2/Assets/_Game/Scripts/Enemies/BodyContactDamage.cs

33 lines
964 B
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令敌人对接触到的目标定期造成伤害。
/// 适用于无攻击动画的简单障碍物、环境危险或测试场景。
/// </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();
}
}
}
}