UGUI之判断是否点在UI上

来源:互联网 发布:帝国cms在线视频 编辑:程序博客网 时间:2024/05/20 11:19
if (Input.touchSupported) {if (Input.touchCount > 0) {if(Input.touches[0].phase== TouchPhase.Began){if (EventSystem.current.IsPointerOverGameObject (Input.GetTouch (0).fingerId))isOnGUGI = true;}} else {isOnGUGI = false;}} else {if (Input.GetMouseButtonDown (0)) {if (EventSystem.current.IsPointerOverGameObject ())isOnGUGI = true;} else if (Input.GetMouseButtonUp (0)) {isOnGUGI = false;}}


简单的处理方式,需要在Resources文件夹下面先放一个EventSystem的Prefab

/// <summary>/// 判断鼠标是否在UI上面/// </summary>/// <returns><c>true</c>, if mouse on U was checked, <c>false</c> otherwise.</returns>public static bool CheckMouseOnUI(){if(EventSystem.current){if(Input.touchSupported && Input.touchCount>0){return EventSystem.current.IsPointerOverGameObject (Input.GetTouch(0).fingerId);}else{return EventSystem.current.IsPointerOverGameObject ();}}else{GameObject.Instantiate(Resources.Load("UI/EventSystem"));}return false;}


0 0
原创粉丝点击