一、实现步骤
1、点击 Window -----> navigation ---》出现如下窗口
2、烘焙场景,在需要巡路的对象上添加Nav mesh Agent组件,
Component ----->navigation ---->Nav mesh Agent
3、在你需要巡路的对象上添加了Nav mesh Agent组件,需要进行合理的设置,如下图,
还需写一个脚本,我这里的脚本是ZhuJueXunLu.cs
代码如下:
using UnityEngine;
using System.Collections;
public class ZhuJueXunLu : MonoBehaviour {
public bool isKaiHui = false; //主角开会
private Vector3 destination;
public void SetIsKaiHui(bool flag){
this.isKaiHui = flag;
}
public bool GetIsKaiHui()
{
return this.isKaiHui;
}
public void Start () {
}
public void Update () {
if(isKaiHui){
destination = SI_Logic.kaiHuiWeiZhi_ZJ;
this.GetComponent<NavMeshAgent>().destination = destination;//目的地
if (this.GetComponent<NavMeshAgent>().hasPath) //还有路程吗?
{
this.animation["Zou"].layer = 1;
this.animation.CrossFade("Zou") ;
}else {
this.animation["DaiJi"].layer = 1;
this.animation.CrossFade("DaiJi");
}
}
}
}