Projext/Assets/5.TestScript/WePonHitBox.cs

37 lines
958 B
C#
Raw Normal View History

2026-01-29 06:58:38 +00:00
using UnityEngine;
using System.Collections.Generic;
public class WeaponHitBox : MonoBehaviour
{
private float _damage;
private bool _isActive;
private List<IDamageable> _hitTargets = new List<IDamageable>();
public void EnableHitBox(float damage)
{
_damage = damage;
_isActive = true;
_hitTargets.Clear(); // <20>ֵθ<D6B5> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʱ<EFBFBD>ȭ<EFBFBD>Ͽ<EFBFBD> <20>ߺ<EFBFBD> Ÿ<><C5B8> <20><><EFBFBD><EFBFBD>
}
public void DisableHitBox()
{
_isActive = false;
}
private void OnTriggerEnter(Collider other)
{
if (!_isActive) return;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (other.TryGetComponent<IDamageable>(out var target))
{
if (!_hitTargets.Contains(target)) // <20><> <20><> <20>ֵθ<D6B5> <20><> <20><> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20>°<EFBFBD>
{
target.TakeDamage(_damage);
_hitTargets.Add(target);
Debug.Log($"{other.name}<7D><><EFBFBD><EFBFBD> {_damage}<7D><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
}
}
}
}