We will create a new component called NavMeshBuilder:
- Create a new file called NavMeshBuilder.cs:
using UnityEngine;using UnityEngine.AI;using System.Collections;using System.Collections.Generic;public class NavMeshBuilder : MonoBehaviour{ // Next steps}
- Add a member variable for storing the navigation surfaces:
public NavMeshSurface[] surfaces;
- Implement the method for building all the NavMesh at once:
public void Build(){ for (int i = 0; i < surfaces.Length; i++) { surfaces[i].BuildNavMesh(); }}
- Implement the method for building all the NavMesh in between frames:
public IEnumerator BuildInFrames(System.Action eventHandler){ for (int i = 0; i < surfaces.Length; i++) { surfaces[i].BuildNavMesh(); yield return null; ...