Target lock???

Hi! I have been trying to get this solved the best way possible but I dont happen to get to a solution…
I have an object that i control in the middle of the scene and want to know how far and in which direction the rest of the the scene objects are. If they are at a certain distance i should be able to “lock” into them and change target between the ones that are in range in some kind of order. For ex: if I have 5 targets, u should swap targets like 1 2 3 4 5 1 2… not 1 2 3 2 3 4 3 1 5 2, etc.

I dont know if i have to do this with raycasting or if there is any other way to do it.

Ty for your time,
Dydra

When you say 1 2 3 4 5 1 2, what are you ordering them by? Distance to the player object in the middle? And in ascending or descending order (is object 1 the furthest, or the closest)?

its has no specific order. I wanted to order them by distance to the target, but the point is that when u swap, it doesnt skipor jump randomly from one target to another