- Home /
Why is it not detecting OnPointEnter
so i followed a tutorial from youtube and i made this Script: using System.Collections; using UnityEngine; using UnityEngine.EventSystems; using System; using UnityEngine.UI;
public class ItemSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private Item _item;
public Item Item
{
get { return _item; }
set
{
_item = value;
if (_item == null)
{
image.enabled = false;
}
else
{
image.sprite = _item.Icon;
image.enabled = true;
}
}
}
[SerializeField] Image image;
[SerializeField] ItemToolTip tooltip;
protected virtual void OnValidate()
{
if (image == null)
image = GetComponent<Image>();
if (tooltip == null)
tooltip = FindObjectOfType<ItemToolTip>();
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("Slot Detected!");
if (Item is EquippableItem)
{
tooltip.ShowTooltip((EquippableItem)Item);
}
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("You Exit");
tooltip.HideTooltip();
}
}
my problem is that it is not detecting the OnPointEnter method and i am not getting my Debug:log if i hover with my mouse above my "Slot" object
That should be working, try making sure that there's no window (Invisible or otherwise) above your slot object (possibly blocking raycast). $$anonymous$$aby also try turning off maskable for a sec.
Answer by Elango · Feb 12, 2021 at 05:39 PM
IPointerEnterHandler/IPointerExitHandler are correctly implemented and should work fine.
1 - IPointerEnterHandler/IPointerExitHandler is part of EventSystems and will not work without it. Make sure there is an EventSystem on the scene.
2 - At least one parent object (usually Canvas) has a Graphic Raycast component and it is enabled.
3 - There is no other UI element with Raycast Target enabled that covers the slot with its position and size, and it is placed in the hierarchy lower than the slot.
Omg i am so dumb i forgot my EventSystem for my scene xD, sorry for wasting your time
Your answer
Follow this Question
Related Questions
If two PlayerPrefs are on? 2 Answers
How to make my badguy freeze when he hit me? 1 Answer
Error Script, Not found class GameObject 1 Answer
Unity Won't Build Android 0 Answers