Answers for "unity sort by distance"

C#
0

unity sort by distance

//using System.Linq;

 hits = hits.OrderBy(
    x => Vector2.Distance(this.transform.position,x.transform.position)
   ).ToList();

// more efficient
 trees = trees.OrderBy((d) => (d.position - transform.position).sqrMagnitude).ToArray();

//Linqless
 hits.Sort(delegate(Enemy a, Enemy b)
  {return Vector2.Distance(this.transform.position,a.transform.position)
   .CompareTo(
     Vector2.Distance(this.transform.position,b.transform.position) );
 });
Posted by: Guest on June-01-2021

C# Answers by Framework

Browse Popular Code Answers by Language