1、对物体行动区域进行渲染
打开Navigation
如果没有从window下拉列表中找
对选择要渲染的区域,对其layer层进行设定
并对区域的Static进行修改
在Navigation中勾选Navigation Static,在Navigation Area中可以对行动区域进行划分,可在Navigation的Area中添加,
之后打开Navigation的Bake,设置好参数Bake
得到如下
区域渲染就好了
2、为对象添加Nav
3、移动脚本
声明
private NavMeshAgent agent = GetComponent<NavMeshAgent>();
移动
Vector3 point = 目标点坐标;
agent.SetDestination(point);
连续移动的话
if (Input.GetKey(KeyCode.Q)) { agent.SetDestination(point); } if (this.transform.position == new Vector3(232, this.transform.position.y, 246)) { agent.SetDestination(point); } if (this.transform.position == new Vector3(342, this.transform.position.y, 235)) { agent.SetDestination(point); }