Hi,
Raycast gives you not just the gameobject hit but also the distance.
What you could do is inform the hit object that it's hit by the raycast ( and also inform when it's not, like a mouse up and down event), and the object then check the distance to the player, and decide if it needs to show something or not
if you understand the above, where is your struggle in implementing it?
Bye,
Jean