1、网格外连接组件
我们在烘焙地形数据的时候,可以生成网格外连接,但是它是满足条件的都会生成,而且是要在编辑模式下生成。如果我们只希望两个未连接的平面之间只有有限条连接路径可以跳跃过去,并且运行时可以动态添加,就可以使用网格外连接组件
2、网格外连接组件的使用
使用两个对象作为两个平面之间的连接点(起点和终点)
添加Off Mesh Link脚本进行关联(起点和终点任意一个添加脚本即可)
设置参数
private NavMeshAgent agent;
agent = this.GetComponent<NavMeshAgent>();
void Update()
{
if( Input.GetMouseButtonDown(0) )
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
agent.SetDestination(hit.point);
}
}
}
![](https://img-blog.csdnimg.cn/img_convert/98a74d315467e9944ada3f3bd82adcce.png)