I want to create a tooltip that appears when the mouse hovers over a button. I tested it and it follows the mouse just as I want it to but the problem is that when I try putting my cursor over a button, nothing happens. I tried attaching rigidbodies and colliders to it (both 2d and 3d), but nothing happens, even though the button changes colour when the mouse goes over it.
Here’s the code i’m using. The script is attached to the button object, but there’s nothing in the console from debug.
For Ui Elements you want to use IPointer*Handler instead.
For example:
using UnityEngine;
using UnityEngine.EventSystems;
public class MouseMoveBehaviour : MonoBehaviour, IPointerMoveHandler {
public void OnPointerMove(PointerEventData eventData)
{
Debug.Log("mouse moving");
}
}
For an overview of all available interfaces refer to this list.
Can you explain more about your specific scenario?
Do you mean detecting only specific objects which the mouse interacted with?
The callback function OnPointer* is invoked when the respective interaction happens on the object the script is attached to or a child of it.
If you want to specific children you have to disable the “raycast target” property of the Image components:
This will disable all the interactions, so you might not want this.
For more fine-grained control you would could implement the interface multiple times and implement some custom logic - but it really depends on what exactly you want to do.
No, I have a thing where a tooltip appears under the cursor when the mouse is over a button. This tooltip is a panel and gives more info about the button so i can use icons on the button instead of text. But if i put the tooltip directly under the cursor, then the button thinks the cursor is no longer over it because it’s over the panel instead, so the panel deactivates, which causes the cursor to be over the button which activates the panel and so on.