몬스터 추격범위 추가, 플레이어 탐지 범위 리팩토링

This commit is contained in:
Mingu Kim
2025-02-10 22:10:03 +09:00
parent 21a173864f
commit 8ffb5deb5d
9 changed files with 197 additions and 9 deletions

View File

@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class Eyesight : MonoBehaviour
{
[SerializeField]
private MonsterBase _monsterBase;
// private bool _isDetect;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
// TODO : 플레이어 감지하면 따라가기
_monsterBase.IsDetect = true;
Debug.Log("감지됨");
if (_monsterBase.IsDetect)
{
_monsterBase.Detect(other.gameObject);
// _monsterBase.IsWalking = false;
}
}
}
// 단순 플레이어 태그 기준 따라가는 코드
private void FixedUpdate()
{
// 타겟의 위치에서 내 현제 위치를 뺌
// UnityEngine.Vector2 direction = target.transform.position - transform.position;
// 방향 * 속도 * 시간간격
// transform.Translate(direction.normalized * speed * Time.deltaTime);
// animator.SetBool("Iidle", true);
}
private void OnTriggerExit2D(Collider2D other)
{
_monsterBase.IsDetect = false;
_monsterBase.IsWalking = true;
}
}
}