is there a way to track multiple objects within range, find out which one is closest and have the player auto target it, for the purpose of shooting it?

Hello I’m making a simple 3D game where the player runs run and shoots enemies, however I want to build in an aim assist, so when an enemy if in a certain field of view, and range, it will target the closest enemy. So when the player fires, it will shoot at that enemy. I’m not exactly sure the best way to go about this. I currently know how to have one object track another object. If you put a trigger collider around the player, when and enemy comes into that collider, using a void OnTriggerStay(Collider other) function, shoot a raycast ray from the player to the enemy. Physics.Raycast (Player.position,enemy’s position, range, layermask)
within a certain view, but I do not know how to do this for multiply objects or how to figure out which is the closest and to compensate for objects that are being tracked, leaving the required range. I’m not even sure if Physics.Raycast is the way to go. Any help would be greatly appreciated! thanks

You can trigger and add the objects to an array of targets attached to the player. Then the player can cycle through the array and check which one has the shortest distance to the player.