Unity3D判断鼠标左右滑动

  private Vector2 firstTouch = Vector2.zero;//手指开始按下的位置
   private Vector2 secondTouch =Vector2.zero;//手指拖动的位置

    void OnGUI()
    {
        if (Event.current.type == EventType.mouseDown) { //判断当前手指是按下事件
            firstTouch = Event.current.mousePosition;    //记录开始按下的位置
        }
        if (Event.current.type == EventType.mouseDrag) {    //判断当前手指是拖动事件
            secondTouch = Event.current.mousePosition;    //记录拖动的位置
            if (secondTouch.x < firstTouch.x) {//拖动的位置比按下的位置的x小
                print ("left");
            }
            if (secondTouch.x > firstTouch.x) {//拖动的位置比按下的位置的x大
                print ("right");
            }
            firstTouch = secondTouch;
        }
    }

原文地址:https://www.cnblogs.com/laugher/p/4768554.html