Im trying to use mouse pointer to detect any UI element on my canvas. when pointer enter any UI element, UI_active set true, else UI_active set false. Here is my script:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;// Required when using Event data.

public class UI_AVATAR : MonoBehaviour, IPointerEnterHandler {

public bool  UI_active;

public void OnPointerEnter(PointerEventData eventData)
    Debug.Log("The cursor entered the selectable UI element.");



1 Answer 1


If you really only care about whether the pointer is over any button, not whether it's over a specific button, then I think the method you want is:


IsPointerOverGameObject returns true if (the given) mouse cursor / finger is over any event system object in your UI, serving the role of your UI_active variable.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .