Unity 检测点击UI

UNiTY检测是否点击UI:

Unity 检测点击UI



        EventSystem eventSystem = EventSystem.current;
        PointerEventData pointerEventData = new PointerEventData(eventSystem);
        pointerEventData.position = Input.mousePosition;
        //射线检测ui
        List<RaycastResult> uiRaycastResultCache = new List<RaycastResult>();
        eventSystem.RaycastAll(pointerEventData, uiRaycastResultCache);
        if (uiRaycastResultCache.Count > 0)
        {
            //根据需求还可以附加判断条件
            //foreach(RaycastResult result in uiRaycastResultCache)
            //{
            //    if (result.gameObject == this || result.gameObject == popMenu || result.gameObject ==selfButton.gameObject)
            //        return true;
            //}
            //return false;
            return true;
        }
            return false;

版权声明:本文为WardellBrone原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。