OnPointerEnter and OnPointerExit not working when game is built

Viewed 103

When I hover over a button (the button changes position on hover) in the Editor Player, OnPointerEnter and OnPointerExit work. When I build the game and go and hover over the button it doesn't work. I've enabled Raycast Target and I have no idea how to fix this.

here is the code

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class CardUp : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    private Vector2 normalPos;
    
    void Start()
    {
        normalPos = gameObject.GetComponent<RectTransform>().position;

    }
    
    

    public void OnPointerEnter(PointerEventData eventData)
    {
        LeanTween.move(gameObject, new Vector2(normalPos.x, normalPos.y + 150), 0.3f);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        LeanTween.move(gameObject, new Vector2(normalPos.x, normalPos.y), 0.3f);
    }

1 Answers

Your code should work. Check that you didn't set Object's tag "editor only". Try using event trigger component. It might solve your problem.

I wanted to comment this but I can't since not enough reputation, so I had to write this as an answer

Related