Projext/Assets/Scripts/Enemy/AI/Monster Weapon.cs

77 lines
2.3 KiB
C#
Raw Normal View History

2026-02-04 14:06:25 +00:00
using System.Collections.Generic;
using UnityEngine;
2026-02-03 14:41:49 +00:00
public class MonsterWeapon : MonoBehaviour
{
[Header("무기 설정")]
[Tooltip("이 무기 고유의 공격력 (예: 10)")]
[SerializeField] private float weaponBaseDamage = 10f;
private float _finalDamage;
2026-02-04 14:06:25 +00:00
[SerializeField] private BoxCollider _weaponCollider;
2026-02-03 14:41:49 +00:00
private void Awake()
{
_weaponCollider = GetComponent<BoxCollider>();
_finalDamage = weaponBaseDamage;
2026-02-04 14:06:25 +00:00
//DisableHitBox();
EnableHitBox();
2026-02-03 14:41:49 +00:00
}
public void SetDamage(float monsterStrength)
{
_finalDamage = weaponBaseDamage + monsterStrength;
Debug.Log($"✅ [무기] 데미지 설정됨: 총 {_finalDamage}");
}
public void EnableHitBox()
{
2026-02-04 14:06:25 +00:00
Debug.Log("enabletest");
2026-02-03 14:41:49 +00:00
if (_weaponCollider != null)
{
2026-02-04 14:06:25 +00:00
Debug.Log("setcollider");
2026-02-03 14:41:49 +00:00
_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' 스크립트가 없습니다!");
}
}
}
}