how to bake NavMesh in runtime from script. I searched in Google but did not find.
some rendered scene and buttons including bake
3 回答
Currently, Unity doesn't have a way to bake but NavMesh at runtime BUT there is an experimental package that Unity has that allows you bake a NavMesh at runtime. It is very stable package.
There were tutorials made by Brackeys in collaboration with Unity.
The demo project is available for download on GitHub. You can use in the scripts in there to bake a runtime NavMesh.
I would highly recommend watching the tutorial first.
Here is also the link for Unity's site and tutorials on runtime navmesh.
using UnityEditor.AI; //"Editor" not "Engine"
NavMeshBuilder.ClearAllNavMeshes();
NavMeshBuilder.BuildNavMesh();
AlienCode 的答案非常适合在运行时烘焙 NavMesh,
因为您不能同时拥有两个 using
标签 ( UnityEditor.AI
& UnityEngine.AI
)。
我创建了一个单独的脚本并将其用于烘焙 NavMesh。
我不确定它是否仅适用于编辑器或构建。