Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Mouse X" and "Mouse Y" return in Unity?

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.

like image 326
Dims Avatar asked Oct 20 '25 05:10

Dims


1 Answers

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

like image 84
Fredrik Widerberg Avatar answered Oct 22 '25 19:10

Fredrik Widerberg