Unity3D如何连接NavMesh和NavMeshAgent

Unity3D how to connect NavMesh and NavMeshAgent

我在编辑器中遇到此错误

"SetDestination" can only be called on an active agent that has been placed on a NavMesh. 这些是我在解决问题时尝试的步骤:

  1. 将 NavmeshAgent 变形到 NavMesh 位置
  2. 手动将 NavMeshAgent 移动到 NavMesh
  3. 重新烘焙 NavMesh 并执行上述步骤
  4. 使用 NavMeshAgent 和新的 NavMesh 创建一个盒子
    • 有没有人有我可以使用的任何其他提示?

扭曲导航网格代理的位置有时会导致错误,尤其是当它从一个导航网格转到另一个导航网格时。

这是一个奇怪的错误,但它似乎检测代理是否不在导航网格上,然后禁用并重新启用代理 - 将解决问题(在我的情况下)。

我在扭曲时通过执行以下操作在我的项目中解决了这个问题。

//use some existing reference to your NavMeshAgent
NavMeshAgent agent = PlayerController.instance.GetComponent<NavMeshAgent>(); 

//This will fire when you get the error you're describing.
if (!agent.isOnNavMesh)
{
   Vector3 warpPosition; //Set to position you want to warp to
   agent.transform.position = warpPosition;
   agent.enabled = false;
   agent.enabled = true;
}

我们可以使用navmesh组件 1.导航网格表面 2.导航网格修改器 3. navmesh修改体积 4. 导航网格关闭链接 通过使用这些组件,我们可以轻松连接 navmesh 和 navmeshagent。