캐릭터 오브젝트 파괴 후 발생하는 MonsterBase Null 에러 수정
This commit is contained in:
@@ -5,6 +5,17 @@ namespace TON
|
|||||||
public class Attack : MonoBehaviour
|
public class Attack : MonoBehaviour
|
||||||
{
|
{
|
||||||
private MonsterBase _monsterBase;
|
private MonsterBase _monsterBase;
|
||||||
|
private GameObject target; // target 변수 선언
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
// target 변수 초기화 (예시)
|
||||||
|
target = GameObject.Find("TON.Player"); // Player라는 이름을 가진 게임 오브젝트 찾기
|
||||||
|
if (target == null)
|
||||||
|
{
|
||||||
|
// Debug.LogError("Player not found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetMonsterBase(MonsterBase monsterBase)
|
public void SetMonsterBase(MonsterBase monsterBase)
|
||||||
{
|
{
|
||||||
@@ -12,6 +23,8 @@ namespace TON
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerEnter2D(Collider2D other)
|
private void OnTriggerEnter2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if(target != null) // target이 null이 아닌지 확인
|
||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
@@ -19,8 +32,11 @@ namespace TON
|
|||||||
_monsterBase.IsFinishAttack = false; // 공격 시작 시 FinishAttack 초기화
|
_monsterBase.IsFinishAttack = false; // 공격 시작 시 FinishAttack 초기화
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTriggerExit2D(Collider2D other)
|
private void OnTriggerExit2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (target != null) // target이 null이 아닌지 확인
|
||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
@@ -30,3 +46,4 @@ namespace TON
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -197,11 +197,14 @@ namespace TON
|
|||||||
public void Chasing()
|
public void Chasing()
|
||||||
{
|
{
|
||||||
var target = GameObject.Find("TON.Player").GetComponentInChildren<CharacterBase>();
|
var target = GameObject.Find("TON.Player").GetComponentInChildren<CharacterBase>();
|
||||||
|
if (target != null)
|
||||||
|
{
|
||||||
Vector2 direction = target.transform.position - transform.position; // 타겟과의 방향 계산
|
Vector2 direction = target.transform.position - transform.position; // 타겟과의 방향 계산
|
||||||
_spriteRenderer.flipX = target.transform.position.x < transform.position.x; // 타겟이 왼쪽에 있으면 스프라이트를 왼쪽으로, 오른쪽에 있으면 오른쪽으로 바라보도록 설정
|
_spriteRenderer.flipX = target.transform.position.x < transform.position.x; // 타겟이 왼쪽에 있으면 스프라이트를 왼쪽으로, 오른쪽에 있으면 오른쪽으로 바라보도록 설정
|
||||||
|
|
||||||
transform.Translate(direction.normalized * moveSpeed * Time.deltaTime); // 타겟 방향으로 이동
|
transform.Translate(direction.normalized * moveSpeed * Time.deltaTime); // 타겟 방향으로 이동
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void MonsterSkillLaunch()
|
public void MonsterSkillLaunch()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user