Skip to content

Instantly share code, notes, and snippets.

@PappaBjorn
Created January 31, 2020 16:20
Show Gist options
  • Save PappaBjorn/3c90854ca5eef496260e573800be43ec to your computer and use it in GitHub Desktop.
Save PappaBjorn/3c90854ca5eef496260e573800be43ec to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class NavMeshUpdater : MonoBehaviour
{
public NavMeshSurface surface;
public float distanceThreshold = 5f;
void Awake()
{
surface.BuildNavMesh();
UpdateNavMesh();
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance(transform.position, surface.transform.position) >= distanceThreshold)
UpdateNavMesh();
}
void UpdateNavMesh()
{
surface.RemoveData();
surface.transform.position = transform.position;
surface.BuildNavMesh();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment