-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavMeshPathGizmo.cs
More file actions
35 lines (30 loc) · 1.12 KB
/
NavMeshPathGizmo.cs
File metadata and controls
35 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Draws the agent's path as Gizmo.
using UnityEngine;
using UnityEngine.AI;
namespace uMMORPG
{
[RequireComponent(typeof(NavMeshAgent))]
public class NavMeshPathGizmo : MonoBehaviour
{
void OnDrawGizmos()
{
// can't cache agent because reloading script sometimes clears cached
NavMeshAgent agent = GetComponent<NavMeshAgent>();
// get path
NavMeshPath path = agent.path;
// color depends on status
Color color = Color.white;
switch (path.status)
{
case NavMeshPathStatus.PathComplete: color = Color.white; break;
case NavMeshPathStatus.PathInvalid: color = Color.red; break;
case NavMeshPathStatus.PathPartial: color = Color.yellow; break;
}
// draw the path
for (int i = 1; i < path.corners.Length; ++i)
Debug.DrawLine(path.corners[i-1], path.corners[i], color);
// draw velocity
Debug.DrawLine(transform.position, transform.position + agent.velocity, Color.blue, 0, false);
}
}
}