Hi,
I have a list of game objects that I sort by distance.
_enemyList.Sort(ByDistance);
function ByDistance(a: GameObject, b: GameObject) : int
{
var dstToA = Vector3.Distance(_player.transform.position, a.transform.position);
var dstToB = Vector3.Distance(_player.transform.position, b.transform.position);
return dstToA.CompareTo(dstToB);
}
But what I want to do is to sort them by distance and only if they are active.
Do I then need to call again?
_enemyList.Sort(ByActive);
function ByActive(a: GameObject, b: GameObject) : int
{
var activeA = a.activeSelf;
var activeB = b.activeSelf;
return activeA.CompareTo(activeB);
}
?
↧