Unity用坐标来判断是否点击在UI上,并调用
2018-01-16 11:43
1186 查看
if (Input.GetMouseButtonDown(1)) { //EventSystem.current就是场景中的EventSystem PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current); eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y); List<RaycastResult> results = new List<RaycastResult>(); EventSystem.current.RaycastAll(eventDataCurrentPosition, results); if (results.Count > 0) { results[0].gameObject.GetComponent<Button>().onClick.Invoke(); } } if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)) { #if IPHONE || ANDROID if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #else if (EventSystem.current.IsPointerOverGameObject()) #endif Debug.Log("当前触摸在UI上" + EventSystem.current.currentSelectedGameObject.name); else Debug.Log("当前没有触摸在UI上"); }
相关文章推荐
- unity 判断触摸坐标是否落在ui上
- Unity判断是否点击到UI、3D物体
- Unity中判断鼠标是否点击到了UI
- unity 判断是否点击到了UI上
- 【Unity】UGUI如何判断鼠标或者手指是否点击到UI上
- unity 判断触摸坐标是否落在ui上
- 【Unity】UGUI如何判断鼠标或者手指是否点击到UI上
- unity 点击Ended状态判断是否点击在UI上
- unity 判断鼠标或者手指是否点击在UI上
- 【NGUI】Unity中如何判断NGUI中当前鼠标是否点击UI上
- Unity_UGUI判断鼠标或者手指是否点击在UI上(三)
- UGUI研究院之判断鼠标或者手指是否点击在UI上
- UGUI研究院之判断鼠标或者手指是否点击在UI上
- UGUI - 判断是否点击在UI 上 Bug,IsPointerOverGameObject()在移动端检测失败
- Unity如何判断Ui是否被Touch
- Unity中UGUI中获取鼠标点击位置以及UI物体的屏幕坐标
- UGUI -(unity3d 5)判断是否点击在UI 上 Bug,IsPointerOverGameObject()在移动输入模式检测失败
- UGUI防止穿透和判断点击的是否是UI
- UnityUI判断当前焦点是否在输入文本框
- UGUI判断鼠标或者手指是否点击在UI上