Projext/Assets/5.TestScript/WePonHitBox.cs

41 lines
1.1 KiB
C#
Raw Normal View History

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