I am using the OverlapSphere to get enemies for my targeting system.
here is my code
The problem is that it does not sort by distance. it just gets the one closest to you. How would I add sort by distance in this script?
There are a couple of things here- you'd need to restructure the way the enemy finder works, since at the moment it can only return a single enemy! You first need to make it return an array or a list (preforably a List, for simplicity's sake), then populate the list in the function.
First up, put 'using System.Collections.Generic' at the top, so that you have generics (which are really useful).
This will give you a list of Transforms which you can iterate through with a Foreach, and which will be sorted in order of distance!
answered Nov 08 '11 at 04:17 AM