ProjectZ/Assets/Scripts/Common Scripts/NavMeshExtensions.cs

23 lines
678 B
C#
Raw Normal View History

2024-02-19 21:00:36 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public static class NavMeshExtensions
{
public static float GetPathRemainingDistance(this NavMeshAgent navMeshAgent)
{
if (navMeshAgent.pathPending ||
navMeshAgent.pathStatus == NavMeshPathStatus.PathInvalid ||
navMeshAgent.path.corners.Length == 0)
return -1f;
float distance = 0.0f;
for (int i = 0; i < navMeshAgent.path.corners.Length - 1; ++i)
{
distance += Vector3.Distance(navMeshAgent.path.corners[i], navMeshAgent.path.corners[i + 1]);
}
return distance;
}
}