Pro_Unit

NavMeshExtensions

Apr 25th, 2022
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. namespace Common
  2. {
  3.     using UnityEngine;
  4.     using UnityEngine.AI;
  5.  
  6.     public static class NavMeshExtensions
  7.     {
  8.         public static Vector3 ToNavMesh
  9.             (this Vector3 value, float maxDistance = float.MaxValue, int allAreas = NavMesh.AllAreas)
  10.             =>
  11.             NavMesh.SamplePosition(value, out NavMeshHit hit, maxDistance, allAreas)
  12.                 ? hit.position
  13.                 : value;
  14.     }
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment