- Home /
Using a Parameterized arraylist (C#)???
I am trying to write a function to get all enemies with tag "Enemy" within range lockOnDistance, and return the list of them. I don't know how many enemies there will be in range, but I want to check the number of them so I can check the boolean version of this (i.e. "Are there enemies in range?" (is the size == 0)), so I have to use an arraylist instead of an array unless I want to go through every enemy and get the number in range (i,e, the size of the array), then go BACK THROUGH THEM ALL AGAIN and add them to the array, and surely there's a better way than that
Issues:
1) Why won't it let me say ArrayList?
2) It doesn't recognize ArrayList.add(E)????
Answer by getyour411 · Mar 23, 2014 at 06:59 PM
Dont use either, use Lists (or the arrays returned by functions, such as...) check out Overlapsphere, then iterate over the colliders it returns to find actual Enemy units and go from there.
Edit: Don't forget to add using System.Generic.Collections; to the top of your C# class to use Lists.
Thanks! This (and googling to find out that I have to include System.Collections.Generic) helped me finish the function :)
Your answer
Follow this Question
Related Questions
Can a tagged object exclude itself from FindGameObjectWithTag? 3 Answers
Distribute terrain in zones 3 Answers
Check if Item is in array list C Sharp 1 Answer
Add to Array 1 Answer
Identifier Expected Error ArrayList -1 Answers