Aggro behavior for RTS game

Hello,
I’m working on a RTS game using Unity - and I was wondering regarding how to implement the following:

In my game I plan to have up to around 60 friendly units and about 150 enemies.
All enemies/friendly units that a unit from the opposite team comes in range, and has a clear line of sight with - automatically attacks the target, considering the following:

  1. All units can have varying ranges of sight.
  2. A unit can always target only 1 unit
  3. Once a unit has left the range of another unit, it can not attack it

Now I have come up with 2 solutions, and I was wondering which is the best way (or if there is a 3rd, better way) to do it:

  1. Put a sphere trigger collider on all units, and keep track of all units coming in and out of trigger events - every update I run through all the units inside my collider and fire ray casts to see that the unit has a clear LOS on the other unit.
  2. For every unit every update I go through all enemy units and check if they are in range. If a unit is in range, I fire a raycast and check if it’s visible.

Thanks!

Two things I’d do to modify the approach there:

  1. Use Physics.OverlapSphere (Unity - Scripting API: Physics.OverlapSphere) instead of sphere colliders to do your range checking.

  2. Make sure the delay is offset somewhat. Making them only update every 500ms is great, but if they all trigger on the same moment you’re still going to have a framerate drop. (Chances are you’re already doing this, I just wanted to include it in case)