2026-02-13 09:11:54 +00:00
|
|
|
|
using UnityEngine; // 유니티 기능을 불러올거에요 -> UnityEngine을
|
|
|
|
|
|
|
|
|
|
|
|
public class MonsterWeapon : MonoBehaviour // 클래스를 선언할거에요 -> 일반 몬스터 무기를
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField] private float baseDamage = 10f; // 변수를 선언할거에요 -> 기본 데미지를
|
|
|
|
|
|
private float finalDamage; // 변수를 선언할거에요 -> 최종 데미지를
|
|
|
|
|
|
private BoxCollider col; // 변수를 선언할거에요 -> 콜라이더를
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake() // 함수를 실행할거에요 -> 초기화 Awake를
|
|
|
|
|
|
{
|
|
|
|
|
|
col = GetComponent<BoxCollider>(); // 가져올거에요 -> 박스 콜라이더를
|
|
|
|
|
|
finalDamage = baseDamage; // 설정할거에요 -> 초기 데미지를
|
|
|
|
|
|
EnableHitBox(); // 실행할거에요 -> 일단 켜두기를
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetDamage(float amount) => finalDamage = amount; // 함수를 선언할거에요 -> 데미지 설정을
|
|
|
|
|
|
public void EnableHitBox() { if (col != null) col.enabled = true; } // 함수를 선언할거에요 -> 판정 켜기를
|
|
|
|
|
|
public void DisableHitBox() { if (col != null) col.enabled = false; } // 함수를 선언할거에요 -> 판정 끄기를
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other) // 함수를 실행할거에요 -> 충돌 감지를
|
|
|
|
|
|
{
|
|
|
|
|
|
if (other.CompareTag("Player")) // 조건이 맞으면 실행할거에요 -> 플레이어라면
|
|
|
|
|
|
{
|
|
|
|
|
|
var hp = other.GetComponent<IDamageable>(); // 가져올거에요 -> 체력 인터페이스를
|
|
|
|
|
|
if (hp != null) { hp.TakeDamage(finalDamage); DisableHitBox(); } // 실행할거에요 -> 데미지를 주고 판정을 끄기를
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|