Show GUI only when looking at an object?

I have a script with a GUI health bar attatched to an object, that changes when hit by rockets. Is it possible that the player can see that GUI only when looking at said object, and no other time? I’ve tried using Raycasting, but that only checks the shortest path between the player and the object, not the players line of sight.

I’d suggest using the Renderer.isVisible attribute. Attach it to the object and tie that into the GUI. Documentation is here: Unity - Scripting API: Renderer.isVisible