Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity know when mouse on ui

using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;


public static bool IsPointerOverUIElement()
    {
        var eventData = new PointerEventData(EventSystem.current);
        eventData.position = Input.mousePosition;
        var results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventData, results);
        return results.Where(r => r.gameObject.layer == 5).Count() > 0;
    }
 
PREVIOUS NEXT
Tagged: #unity #mouse #ui
ADD COMMENT
Topic
Name
1+6 =