0
\$\begingroup\$

I got the following question:

How to show an image as Tooltip in a Unity3D? The image should only be visible if the user hovers over the 3d object.

Thanks in advance,

hidayah

\$\endgroup\$
3
  • \$\begingroup\$ Your recent edit changed your question from a conceptual question to a "debug my code" question. That's a completely different question. Please post it as a new question. When you do that, please don't forget what "error" you have. Which means to tell your readers which line generates the error and the exact wording of the error message. \$\endgroup\$
    – Philipp
    May 24, 2023 at 11:07
  • \$\begingroup\$ ...which, as I just found out, you already did 2 days ago. Please don't post the same question multiple times. \$\endgroup\$
    – Philipp
    May 24, 2023 at 11:24
  • \$\begingroup\$ Thank you for reminding me. I will do it better next time. \$\endgroup\$ May 25, 2023 at 13:40

1 Answer 1

1
\$\begingroup\$

First we need to find out what object the mouse cursor is pointing at. You can do that by combining Input.mousePosition with camera.ScreenPointToRay and Physics.Raycast. Keep in mind that the object needs a collider for raycast hits to register. Here is an example from the official manual.

Now that we got the position and the object, we need to visualize the tooltip itself. I recommend to do that with a fullscreen UI canvas with a single panel that contains whatever you currently want to show. You can control the panel's position by getting its RectTransform component and setting its position to the Input.mousePosition.

\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .