Skip to content

Instantly share code, notes, and snippets.

@mminer
Created September 8, 2021 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mminer/be4d87b8f702b9b4ff010fc09bb6a017 to your computer and use it in GitHub Desktop.
Save mminer/be4d87b8f702b9b4ff010fc09bb6a017 to your computer and use it in GitHub Desktop.
Unity NavMeshPath extension function to calculate its length.
public static float GetLength(this NavMeshPath path)
{
if (path == null || path.status == NavMeshPathStatus.PathInvalid || path.corners.Length <= 1)
{
return Mathf.Infinity;
}
var length = 0f;
for (var i = 1; i < path.corners.Length; i++)
{
length += Vector3.Distance(path.corners[i - 1], path.corners[i]);
}
return length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment