NavMeshAgent 클래스에 있는
SetDestination()메서드
- 메서드에게 도착할 위치(Vector3)를 전달하면, 에이전트가 자동으로 경로를 계산하고 해당 위치로 이동하도록 지시 함.
예시)
using UnityEngine;
using UnityEngine.AI;
public class MoveToTarget : MonoBehaviour
{
public Transform target; // 목표지점의 Transform 컴포넌트
private NavMeshAgent agent; // NavMeshAgent 컴포넌트
void Start()
{
// 시작할 때 NavMeshAgent 컴포넌트 호출
agent = GetComponent<NavMeshAgent>();
}
void Update() // 매 프레임마다 목표 지점으로 이동
{
//특정 이벤트 발동 조건 로직 내에
agent.SetDestination(target.position);
}
}