I hope I'm being oblivious, but is there a way to iterate over all the members of a Layer? I'd like to linecast at each one.
If not, what is the usual way to keep or dynamically create a collection of gameobjects for frequent iteration - Line of Site calculations in this case. Store them in a Singleton?
There is a function to get all game objects with a certain Tag, but not a corresponding one for a given Layer.
Probably the easiest would be to have each item add and remove itself from a static list when it is created and destroyed (or a non-static list in a singleton).
e.g.
public class MyLinecastTarget : MonoBehaviour
{
public static List<MyLinecastTarget> activeTargets = new List<MyLinecastTarget>();
void OnEnable()
{
activeTargets.Add( this );
}
void OnDisable()
{
activeTargets.Remove( this );
}
}