|
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?
(comments are locked)
|
|
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! how would I do it so that when I hit shift it would... for say make the enemy turn red?
Nov 08 '11 at 12:33 PM
Babilinski
Which enemy? I assume you have several. I'm not specifying any particular way of using this function, by the way- just call it in your script, and then iterate through the members however you like. To make the enemy turn red, you'd have to change some value in its material- I can't really say exactly how, because that differs from renderer to renderer.
Nov 08 '11 at 12:51 PM
syclamoth
Could you give me a code snippet on how to alternate the enemy's?
Nov 08 '11 at 12:57 PM
Babilinski
huh? Now I have absolutely no idea what you're talking about.
Nov 08 '11 at 01:20 PM
syclamoth
how do I iterate through with a Foreach?
Nov 08 '11 at 09:51 PM
Babilinski
(comments are locked)
|
