37 lines
958 B
C#
37 lines
958 B
C#
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(); // 휘두를 때마다 초기화하여 중복 타격 방지
|
|
}
|
|
|
|
public void DisableHitBox()
|
|
{
|
|
_isActive = false;
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!_isActive) return;
|
|
|
|
// 적에게 데미지 입히기
|
|
if (other.TryGetComponent<IDamageable>(out var target))
|
|
{
|
|
if (!_hitTargets.Contains(target)) // 한 번 휘두를 때 한 명당 한 번만 맞게
|
|
{
|
|
target.TakeDamage(_damage);
|
|
_hitTargets.Add(target);
|
|
Debug.Log($"{other.name}에게 {_damage}의 물리 데미지!");
|
|
}
|
|
}
|
|
}
|
|
} |