How to make an object visible when the player is pointing at a certain spot?

I’m trying to make so when the player points at a spot, a translucent version of an object appears.
Imagine a computer, if you point at the usb slot, a green, transparent flash drive that is plugged into that slot appears. If you look away it vanishes.

How could this be accomplished? The only way I could think to do this would be with Raycasts and SendMessages to determine when the object should be SetActive, but that seemed overcomplicated and expensive.

The Raycast/SendMessage is not that complicated. But if you want an alternative, you can check the angle between whatever you use for ‘vision’ and the angle between the player and each object. If it is smaller than some threshold, the player is pointing at that objct.

  • Tag all object that might be looked at with the same tag
  • Use GameObject.FindGameObjectsWithTag() in Start() to get a list of all possible items to be look at.
  • Use transform.forward or some other vector that represents sight for your player.
  • Use a second vector between the player and each object
  • If the Vector3.Angle() is less than some threshold, (and you don’t have to worry about blocking objects), then the object are “seen” and a translucent version can appear.