Constantly search for enemys with certain tag, if close enough set nav agent destination to it

Hey,

I have been creating a “lane” type game, think of the league of legends minions. Where you sent fighters down a lane towards the enemy base, and they enemy does the same back to you.

I am up to the part of programming the minions to attack each other on sight, I have the agent currently set to the enemy base, however I want to set it to the closest minion that comes into range of there “sight” and for them to move towards them (and then i can program the attacking!)

I am guessing I am to store the minions into an array that it finds the closest out of them, however I am not too sure how to do this, also minions will always be spawning so it needs to be constantly updating!

Any help is hugely appreciated. Thank you.

You’re on the right track. What I would do is have a sort of global “MinionManager” component in the scene that, when each minion is spawned, it would register itself with the manager. Then when it needs to check, it can just get the list from the manager.