Projext/Assets/Scripts/Enemy/AI/Monster Weapon.cs
2026-02-04 23:06:25 +09:00

77 lines
2.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class MonsterWeapon : MonoBehaviour
{
[Header("무기 설정")]
[Tooltip("이 무기 고유의 공격력 (예: 10)")]
[SerializeField] private float weaponBaseDamage = 10f;
private float _finalDamage;
[SerializeField] private BoxCollider _weaponCollider;
private void Awake()
{
_weaponCollider = GetComponent<BoxCollider>();
_finalDamage = weaponBaseDamage;
//DisableHitBox();
EnableHitBox();
}
public void SetDamage(float monsterStrength)
{
_finalDamage = weaponBaseDamage + monsterStrength;
Debug.Log($"✅ [무기] 데미지 설정됨: 총 {_finalDamage}");
}
public void EnableHitBox()
{
Debug.Log("enabletest");
if (_weaponCollider != null)
{
Debug.Log("setcollider");
_weaponCollider.enabled = true;
Debug.Log("🔴 [무기] 공격 판정 ON! (휘두르기 시작)"); // 로그 추가
}
}
public void DisableHitBox()
{
if (_weaponCollider != null)
{
_weaponCollider.enabled = false;
Debug.Log("⚪ [무기] 공격 판정 OFF (휘두르기 끝)"); // 로그 추가
}
}
// ⭐ 여기가 핵심! 닿는 모든 것을 기록함
private void OnTriggerEnter(Collider other)
{
// 1. 무엇이든 닿으면 일단 로그를 찍음 (범인 색출)
Debug.Log($"💥 [충돌 감지] 무기가 닿은 것: {other.name} / 태그: {other.tag}");
if (other.CompareTag("Player"))
{
PlayerHealth playerHealth = other.GetComponent<PlayerHealth>();
if (playerHealth != null)
{
if (!playerHealth.isInvincible)
{
playerHealth.TakeDamage(_finalDamage);
Debug.Log($"⚔️ [적중] 플레이어 체력 깎임! (-{_finalDamage})");
}
else
{
Debug.Log("🛡️ [방어] 플레이어가 무적 상태입니다.");
}
DisableHitBox();
}
else
{
Debug.LogError("⚠️ [오류] 플레이어 태그는 있는데 'PlayerHealth' 스크립트가 없습니다!");
}
}
}
}