给角色添加 NavMeshAgent agent 组件
创建脚本获取NavMeshAgent agent组件
public class Girl : MonoBehaviour {
private NavMeshAgent agent;
public Transform cube;
private Animator an;
// Use this for initialization
void Start () {
agent=GetComponent<NavMeshAgent>();
an = GetComponent<Animator>();
agent.destination = cube.position;
}
将目标位置给到destination属性
角色就会朝目标走去