38 lines
2.2 KiB
C#
38 lines
2.2 KiB
C#
using UnityEngine; // 유니티 기능을 불러올거에요 -> UnityEngine을
|
|
|
|
public class BossWeapon : MonoBehaviour // 클래스를 선언할거에요 -> 보스 무기를
|
|
{
|
|
[Header("설정")] // 인스펙터 제목을 달거에요 -> 설정을
|
|
[SerializeField] private float damage = 20f; // 변수를 선언할거에요 -> 데미지를
|
|
[SerializeField] private string targetTag = "Player"; // 변수를 선언할거에요 -> 타겟 태그를
|
|
|
|
private Rigidbody rb; // 변수를 선언할거에요 -> 리지드바디를
|
|
private Collider col; // 변수를 선언할거에요 -> 콜라이더를
|
|
private bool isThrown; // 변수를 선언할거에요 -> 던져짐 여부를
|
|
|
|
private void Awake() // 함수를 실행할거에요 -> 초기화를
|
|
{
|
|
rb = GetComponent<Rigidbody>(); // 가져올거에요 -> 리지드바디를
|
|
col = GetComponent<Collider>(); // 가져올거에요 -> 콜라이더를
|
|
}
|
|
|
|
public void ThrowBall() { isThrown = true; if (col) col.isTrigger = true; } // 함수를 선언할거에요 -> 던짐 처리를 (통과)
|
|
public void PickUpBall() { isThrown = false; if (col) col.isTrigger = true; } // 함수를 선언할거에요 -> 줍기 처리를 (통과)
|
|
|
|
private void OnTriggerEnter(Collider other) // 함수를 실행할거에요 -> 트리거 충돌 시
|
|
{
|
|
if (isThrown && other.CompareTag(targetTag)) ApplyDamage(other.gameObject); // 조건이 맞으면 실행할거에요 -> 플레이어 피격을
|
|
else if (isThrown && other.CompareTag("Ground")) if (col) col.isTrigger = false; // 조건이 맞으면 실행할거에요 -> 바닥이면 물리로 전환을
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision col) // 함수를 실행할거에요 -> 물리 충돌 시
|
|
{
|
|
if (isThrown && col.gameObject.CompareTag(targetTag) && rb.velocity.magnitude > 2f) ApplyDamage(col.gameObject); // 조건이 맞으면 실행할거에요 -> 굴러서 부딪히면 데미지를
|
|
}
|
|
|
|
private void ApplyDamage(GameObject target) // 함수를 선언할거에요 -> 데미지 적용을
|
|
{
|
|
var hp = target.GetComponent<IDamageable>(); // 가져올거에요 -> 체력 스크립트를
|
|
if (hp != null) hp.TakeDamage(damage); // 실행할거에요 -> 데미지 함수를
|
|
}
|
|
} |