首先创建一个场景,里面包含地面plane和人物(可以用圆柱体代替)大概做成这样就可以了。
然后要给角色(圆柱体)加上NavMesh Agent组件。
打开AI导航之后选住地面和目标点进行烘焙
勾选上静态的。然后在Bake里面烘焙就行了。`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AINavigation : MonoBehaviour
{
public GameObject target;
private NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
agent.destination = target.transform.position;
}
// Update is called once per frame
void Update()
{
}
把寻路代码赋给圆柱体,target指定正方体。然后效果就有了。