What does “Mouse X” and “Mouse Y” return in Unity?

萝らか妹 提交于 2021-01-28 09:32:43

问题


I wrote the following update:

void Update () {

        if( Input.GetMouseButton(0) )
        {

            if( !dragging )
            {
                dragging = true;

                xDragStart = Input.GetAxis("Mouse X");
                yDragStart = Input.GetAxis("Mouse Y");
            }


            xDrag = Input.GetAxis("Mouse X");
            yDrag = Input.GetAxis("Mouse Y");

            DragValuesText.text = "x = " + xDrag + ", y = " + yDrag;
        }
        else
        {
            if( dragging )
            {
                dragging = false;
            }
        }


    }

and made a Text UI to display DragValuesText. After this I found, that returned values are small while I am dragging and turn to zero if I stop the mouse. Looks like they return delta. But how can I be sure?

In documentation I don't see it is definitely delta. It says it CAN be delta, but how to know or change this fact -- it is not said.


回答1:


Go into Edit -> Project Settings -> Input and check the settings for the Mouse X / Mouse Y axes.

The Type should be "Mouse movement" by default, which means its "mouse delta"

Use Key / Mouse Button for any kind of buttons, Mouse Movement for mouse delta and scrollwheels, Joystick Axis for analog joystick axes and Window Movement for when the user shakes the window.

https://docs.unity3d.com/Manual/class-InputManager.html



来源:https://stackoverflow.com/questions/50889727/what-does-mouse-x-and-mouse-y-return-in-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!