1.给定第一个目标,让其自动寻路
先烘培,前面博客有具体描述如何烘培。
新建一个C#,代码如下:
using UnityEngine;
using System.Collections;
public class womenRun : MonoBehaviour {
private NavMeshAgent agent;
public GameObject target;
// Use this for initialization
void Start () {
//获取组件NavMeshAgent
agent = GetComponent<NavMeshAgent>();
//SetDestination自动寻路函数,targer为目标,transform为目标组件,position为组件上位置
agent.SetDestination(target.transform.position);
}
// Update is called once per frame
void Update () {
}
}
代码挂在人物身上,新建一个cube,把cube挂在人物脚本上,如:
此时,人物可以移动到Cube上