코어, 벽, 적의 생성 및 충돌, 데미지 판정

This commit is contained in:
2026-01-12 13:09:08 +09:00
parent a0cf82e97e
commit 5e2eaee44b
24 changed files with 732 additions and 25 deletions

View File

@@ -0,0 +1,45 @@
using UnityEngine;
using UnityEngine.AI; // NavMesh 기능을 위해 필수
public class EnemyAI : MonoBehaviour
{
private NavMeshAgent _agent;
private Transform _target;
void Awake()
{
_agent = GetComponent<NavMeshAgent>();
}
void Start()
{
// --- 2번 방법: 위치 보정 로직 시작 ---
// 현재 위치에서 반경 2.0f 이내에 가장 가까운 NavMesh가 있는지 검사합니다.
if (NavMesh.SamplePosition(transform.position, out NavMeshHit hit, 2.0f, NavMesh.AllAreas))
{
// 에이전트를 해당 위치로 강제 순간이동(Warp) 시킵니다.
// 이 작업은 에러를 방지하고 에이전트를 활성화합니다.
_agent.Warp(hit.position);
}
else
{
Debug.LogError($"{gameObject.name} 근처에 NavMesh를 찾을 수 없습니다! 스폰 위치를 확인하세요.");
}
// --- 2번 방법 끝 ---
// 기존 타겟(Core) 설정 로직
GameObject coreObj = GameObject.FindWithTag("Core");
if (coreObj != null)
{
_target = coreObj.transform;
}
}
void FixedUpdate()
{
if (_target != null && _agent.isOnNavMesh)
{
_agent.SetDestination(_target.position);
}
}
}