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
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI 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
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
.