1新建一个Cube 设置大小(10,0.5,10),重命名plane;在plane上新建3个cube改名obstacle;新建一个sphere,和一个cube 分别重命名为player,target。Hierarchy面板如下图所示

2 Window>Navigation打开Naviagtion面板,选中3个obstacle设置如下图:
选中plane设置如下图:
5调整障碍物,和目标物体的位置,让其看起来很舒服,如下图所示^_^:


3 新建一个C#脚本,如下:
- public class NavTest : MonoBehaviour
- {
- public Transform target;
- private NavMeshAgent navMeshAgent;
- void Start ()
- {
- navMeshAgent =GetComponent<NavMeshAgent> ();
- }
- void Update ()
- {
- navMeshAgent.destination = target.position;
- }
- }
4为player添加component>Naviagtion>NavMesh Agent组件,并把脚本挂在player上;NavMesh Walkable层为Deault,target拖拽到NavTest中的Target 设置如下图:

5调整障碍物,和目标物体的位置,让其看起来很舒服,如下图所示^_^:

6打开Navigation面板下Bake子面板设置一些参数,参数的解释看手册,点击Bake,然后Ctrl+P简单的寻路就OK了。
The NavMesh Agent component is used in connection with pathfinding, and is the place to put information about how this agent navigates the NavMesh. You can access it in Component->Navigation->Nav Mesh Agent
导航网格代理(NavMesh Agent )组件用于寻路,是存放代理如何在导航网格(NavMesh)中导航的信息的地方。你可以在Component->Navigation->Nav Mesh Agent访问。
-
Radius 半径Agent radius (used for pathfinding purposes only, and can differ from the actual object's radius, typically larger).
代理的半径(仅用于寻路目的,可以跟实际对象的半径大小不一样,一般比实际对象的半径大)。 -
Speed 速度Maximum movement speed with which the agent can traverse the world toward its destination.
代理可以周游世界,走向它的目的地的最大移动速度。 -
Acceleration 加速度Maximum acceleration. 最大加速度。
-
Angular Speed 角速度Maximum rotation speed in (deg/s). 最高转速(度/秒)。
-
Stopping distance
制动距离Stopping distance. The agent will decelerate when within this distance to the destination.
制动距离。到目的地的距离小于这个值,代理减速。 -
Auto Traverse OffMesh Link
自动遍历OffMesh链接Automate movement onto and off of OffMeshLinks.
自动移动并关闭OffMeshLinks -
Auto Repath 自动重新寻路Acquire new path if existing is partial or invalid.
如果现有的部分已失效,获得新的路径。 -
Height 高度The height of the agent (used in debug graphics).
代理的高度(用于调试图形)。 -
Base offset
基本偏移Vertical offset of the collision geometry relative to the actual geometry.
碰撞几何体相对于实际几何体垂直的偏移。 -
Obstacle Avoidance Type
障碍躲避类型The level of quality of avoidance.
躲避的质量水平。 -
NavMesh Walkable
导航网格行走Specifies the types of Navmesh layers that the agent can traverse.
指定代理可以遍历的导航网格层类型。