Help with multiple targets

Hi!
I am trying to create a script for a enemy character. I want it to have multiple targets that it is looking for. And attack when the target/targets are entering a certain radius around it. But how can I make that happen? I am using a navmesh on all the characters in game. I was thinking about using tags but I would have multiple tags that are targets for this enemy.
So question is, how can i go about making this enemy look for multiple targets? I would really like to use tags to decide if the objects that enters the radius is a target or not. But I do not know how.

Thank you!

Depends how complex your game is.
The fastest way, but uses a layer (you only get 32 layers), is to put enemies on a layer (say enemies layer), and then have all objects in that layer added to a global list of available enemies.

For tags, you can start with “enemy” tag on enemy objects, and then have a collider/trigger with the search radius that checks the tag of any object that OnTriggerEnters. If the tag matches, add to list " enemiesInRadius();" When it leaves remove it from the list with OnTriggerExit. When it dies, remove it from the list.

I personally just like to use lists or arrays or dictionaries, and then query those, instead of tags.

Basically, whenever an object is spawned, add it to a list, and when it is destroyed, remove it from the list.

big question and many ways to answer it.
From the sounds of it you want to be able to attack all units within range at the same time.

OnTriggerEnter or OnTriggerStay to populate a list, followed by using a foreach Loop to iterate and deal damage to all those units that are within that list.

  • you may even not need to make a list if you use OnTriggerStay; deal Damage “foreach” unit within “OnTriggerStay”

if your new; I would suggest searching these keywords on youtube/google or Unity scripting reference.

Words to research : OnTriggerStay, foreach Loops, and Lists.