MouseHover doesn't work with OnMouseOver method

39 views Asked by At

In my game in Unity i have to spawn a sprite above a cell in the grid when the mouse goes over it. I've tried using the OnMouseOver method and the BoxCollider2D, but it doesn't work.

This is my current script for the Cell GameObject:

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

[RequireComponent(typeof(BoxCollider2D))]

public class CellManager : MonoBehaviour
{

    void OnMouseEnter()
    {
        //Code (that doesn't execute)
    }

    void OnMouseExit()
    {
        //Code
    }

}

I've learnt a lot about it, i've tried usign EventTrigger and set 'both' on Input System (project settings), with the same result. I've heard about Raycasting and other things but i don't know anything about it and i don't know what i have to do exactly.

1

There are 1 answers

0
Philip John On

You can use Event Trigger Component.

Event Trigger Component

Grid Cell

Results

You have to disable Raycast Target checkbox of hover image if you want to show hover image above a cell.

Hover Image

Hope help you my answer .