41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public class WeaponHitBox : MonoBehaviour
|
|
{
|
|
private float _damage;
|
|
private bool _isActive = false;
|
|
private List<IDamageable> _hitTargets = new List<IDamageable>();
|
|
|
|
public void EnableHitBox(float damage)
|
|
{
|
|
_damage = damage;
|
|
_isActive = true;
|
|
_hitTargets.Clear();
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void DisableHitBox()
|
|
{
|
|
_isActive = false;
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!_isActive || other.CompareTag("Player")) return;
|
|
|
|
// ⭐ [핵심] 몬스터의 감지 영역(Trigger)은 무시하고 '진짜 몸통'만 타격!
|
|
if (other.isTrigger) return;
|
|
|
|
if (other.TryGetComponent<IDamageable>(out var target))
|
|
{
|
|
if (!_hitTargets.Contains(target))
|
|
{
|
|
target.TakeDamage(_damage);
|
|
_hitTargets.Add(target);
|
|
Debug.Log($"<color=green>[Hit]</color> {other.name}의 몸통을 정확히 타격!");
|
|
}
|
|
}
|
|
}
|
|
} |