How can set my target to the 1 I'm aiming?

Hi everyone,
Im working on a target system for my project that targets the enemy that im aiming for and if i aim another enemy or move the camera so it cant target anything it changes target to the other enemy or to nothing respectively. Any clue of how to do this?
Thank you for the attention.