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)???

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.