I am trying to use Event Trigger to access PointerEnter and PointerExit from script. I am trying to create Tool Tips, but I only want the Tool Tips to display if the Button the mouse hovers over is interactable = false.
I can get this to work by dragging and dropping the correct GameObject into the Inspector, but this method does not know whether the button the mouse is over is interactable or not; therefore it always displays the Tool Tip.
Hopefully this makes sense if not I can try and explain better.
Thanks!
You don’t need EventTrigger for accessing PointerEnter and PointerExit through script (you can do it via EventTrigger though). All you need is EventSystem on scene and implementing required interfaces:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ToolTips : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
Button button;
private void Awake() {
button = GetComponent<Button>();
}
public void OnPointerEnter(PointerEventData eventData) {
if (!button.interactable)
ShowToolTips();
}
public void OnPointerExit(PointerEventData eventData) {
if (!button.interactable)
HideToolTips();
}
}
Also if you need only Interactable feature and don’t need Button.onClick, you can just use Selectable component instead of Button
@Zankomag, thanks for the help, not sure if its working yet. Using TextMeshPro, can use use TextReference.text = “words” to change the text in game?
Right now I have this (Ive implemented everything else you said):
public TextMeshProUGUI toolTipT;
public void OnPointerEnter(PointerEventData eventData)
{
if (Button.interactable) { toolTipT.text = “WORDS”; }
}
Does the toolTipT.text need to be in the Update method?