게임 레벨의 내비메시를 베이크한 경우 씬 안에서 이동할 캐릭터를 생성합니다. 실린더로 프로토타입 에이전트를 빌드한 뒤 움직여 보겠습니다. 이 작업은 NavMesh Agent 컴포넌트와 간단한 스크립트를 통해 이루어집니다.
먼저 캐릭터를 생성합니다.
이제 간단한 내비메시 에이전트를 생성했으며 커맨드를 내릴 수 있습니다.
내비메시 에이전트로 실험을 시작하려면 캐릭터 크기와 속도에 맞춰 크기를 조정해야 합니다.
내비메시 에이전트 컴포넌트가 경로 탐색과 캐릭터의 움직임 조절까지 다룹니다. 스크립트에서 내비게이션으로 원하는 목표 포인트를 설정하면 내비메시 에이전트가 나머지 항목을 자동으로 처리합니다.
// MoveTo.cs
using UnityEngine;
using System.Collections;
public class MoveTo : MonoBehaviour {
public Transform goal;
void Start () {
NavMeshAgent agent = GetComponent<NavMeshAgent>();
agent.destination = goal.position;
}
}
다음으로 간단한 스크립트를 빌드하여 또 다른 게임 오브젝트로 지정된 목표와 목표로 설정된 구체에 캐릭터를 보낼 수 있습니다.
MoveTo.cs
)를 생성하고 위의 스크립트로 콘텐츠를 작성합니다.즉, 스크립트에서 NavMesh Agent 컴포넌트의 레퍼런스를 가지고 에이전트를 움직이도록 설정하려면 에이전트의 destination 프로퍼티로 포지션을 할당합니다. 내비게이션 방법에서 내비메시 에이전트로 일반적인 게임플레이 시나리오 해결법에 대한 다양한 예제를 볼 수 있습니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.