Quantcast
Channel: Latest Questions by Griffo
Viewing all articles
Browse latest Browse all 94

Sort list by distance AND by being active

$
0
0
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); } ?

Viewing all articles
Browse latest Browse all 94

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>