Advertisement
Pro_Unit

FindNearWith

May 14th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.30 KB | None | 0 0
  1. public Transform FindNearWith (Transform target)
  2. {
  3.     if (items.Count == 0) return null;
  4.     Func<Transform, float?> getDist = x => Vector3.Distance (x.position, target.position);
  5.     return items.Aggregate ((curMin, x) => (curMin == null || (getDist (x) ?? float.MaxValue) < getDist (x) ? x : curMin));
  6. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement