How can an UI Element know on which 3D Object it is pointing?

Hi there,
How can I realise, for example in a FirstPerson shooter, when an enemy is the area of the crosshair (so that I can play a sound or change the crosshair color…). So that a UI element recognizes what it is showing (from the perspective of the player). I really have no idea at all, I hope that the question is precise enough and I would be very happy to receive an answer! :wink: Thank you in advance, greetings Luca

Assuming that your UI is a camera overlay, you can use a Raycast from the Camera.transform.forward and check for Enemy Layers as collision. Then write a function to change your crosshair color / UI if the raycast is colliding with an enemy. This could prove expensive if you are raycasting every frame so looking into an alternative might be ideal, but its a start. Maybe LineCasting can work too.