Unity 手指检测屏幕点击区域

if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
        {

    /*        Ray ray = uiCamera.ScreenPointToRay(Input.mousePosition);
            var hitCount = Physics.RaycastNonAlloc(ray,m_hit,1000, m_layerMask);
            Debug.DrawRay(ray.origin,ray.direction*1000,Color.red,10);
            if (hitCount > 0)
            {
                Debug.Log("IsPickDown......");
                Debug.DrawLine(ray.origin, m_hit[0].point, Color.green);
                GameObject hitObj = m_hit[0].collider.gameObject;
                
                if (hitObj.tag == "DispatchMap")
                {
                }
            }*/

      /*      RaycastHit2D hit = Physics2D.Raycast(uiCamera.ScreenToWorldPoint(Input.mousePosition), uiCamera.transform.forward, 1000);
            if (hit.collider != null)
            {
                print("按下3");
            }*/
#if UNITY_ANDROID || UNITY_IPHONE
            if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#else
            if (EventSystem.current.IsPointerOverGameObject())
#endif
            {
                PointerEventData pe = new PointerEventData(EventSystem.current);
                pe.position = Input.mousePosition;
                EventSystem.current.RaycastAll(pe, m_hit);
                bool isClose = true;
                for (int i = 0; i < m_hit.Count; i++)
                {
                    if (m_hit[i].gameObject.tag == "CommonTipBg")
                    {
                        isClose = false;
                        break;
                    }
                }
                if (isClose)
                {
                    LuaManager.Instance.CSharpCallLuaLogic("CloseCommonTipsFunc");
                }
            }
        }

  用于可穿透点击:点击区域并且可以出现下面的点击事件

posted @ 2022-11-10 19:17  姿态H  阅读(574)  评论(0编辑  收藏  举报