23 lines
678 B
C#
23 lines
678 B
C#
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;
|
|
}
|
|
} |