1. 程式人生 > >Unity UGUI 判斷滑鼠是否點選到UI上

Unity UGUI 判斷滑鼠是否點選到UI上

private bool IsTouchedUI()
    {
        bool touchedUI = false;
        //TODO 移動端
        if (Application.isMobilePlatform)  
        {
            if (Input.touchCount > 0 && EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                touchedUI = true;
            }
        }
        //TODO PC端
        else if (EventSystem.current.IsPointerOverGameObject())
        {
            touchedUI = true;
        }
        return touchedUI;
    }