在PC上使用下面命令可以很容易实现判断是否在UGUI上
| 1 | if (EventSystem.current.IsPointerOverGameObject()) | 
但在移动端,该方法失灵,即便使用以下方法也无效。
| 1 | if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) | 
这时候就要用射线来检测了,,上代码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |     /// <summary>     /// 是否鼠标在UGUI上     /// </summary>     /// <returns></returns>     public static bool IsPointerOverUIObject()     {         if (EventSystem.current == null) return false;         PointerEventData pointerEventData = new PointerEventData(EventSystem.current);         pointerEventData.position = Input.mousePosition;         List<RaycastResult> results = new List<RaycastResult>();         EventSystem.current.RaycastAll(pointerEventData, results);         return results.Count > 0;     } | 
- 本文固定链接: http://www.u3d8.com/?p=1949
- 转载请注明: 网虫虫 在 u3d8.com 发表过





