U3D判断触摸拖动的方向

2023-08-24 13:39:44 浏览数 (2)

代码语言:javascript复制
    Vector3 m_startPos;
    Vector3 m_endPos;
    bool m_down = false;
    void FingerSwipe()
    {
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (m_down == false)
                {
                    m_down = true;
                    m_startPos = Input.mousePosition;
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                m_down = false;
                m_endPos = Input.mousePosition;
                if (m_startPos.x - m_endPos.x > 10.0f)
                {
                    Debug.Log("left");
                }
                else if (m_endPos.x - m_startPos.x > 10.0f)
                {
                    Debug.Log("right");
                }
                m_startPos = m_endPos;
            }
        }
    }

FingerSwipe放到update中

0 人点赞