How to retrieve all player units? (34282)

How to retrieve all player units?

Should I tag them with “player unit” for example, and then use GameObject.FindGameObjectsWithTag.
Or should I add a player unit to a static list in C# each time a new unit is created, so I won’t have to do additional work then to get all player units when needed.

Could you guys give me opinions on both please? The first one is simpler and the second one might be faster.

Do the second one. Every time you create a unit, you can keep track of it- so why make the program do more work?

1 Answer

1

you can use RaycastAll

Look here for more info on Raycast

That would work in theory, but would be extremely difficult and tiresome in practice.