Input.GetMouseButton (0). DeltaPosition

hello guys!

does anyone know if there is a function in unity as Input.GetTouch (0). deltaPosition but for the mouse?!
for example:
Input.GetMouseButton (0). DeltaPosition

No, you have to make it in your own.
Have lastPosition and currentPosition as vars and pass them thru your update as…

currentPositon = Input.mousePosition;
deltaPositon = currentPositon-lastPositon;
lastPositon = currentPosition;
2 Likes

thanks for the reply.

But I need to know the y-coordinate of the mouse cursor to pass it to a object.transform.position.y.

so the oject follows the mouse cursor to a vertical axis of the screen!

how do you advise me to do?!

I know this is little bit late but hopes this help you.

(Note: Create a camera gameobject in the scene. Attached this script to the camera gameobject. Then create an empty gameobject and name it “horizontalPivot”. Make the camera gameobject child of that horizontalPivot gameobject. Of course, you must first assign the horizontalPivot that you had created earlier to the camera object variable in the inspector)

//Start Here

var horizontalPivot : GameObject;
var lastMousePosition = 0;

  if(Input.GetMouseButton(1))
        {
         
            Debug.LogWarning("lastXValue: " + lastMousePosition);
            //Horizontal Rotate
            if(Input.GetMouseButtonDown(1))
            {
                var prevMousePosition : Vector2 = Input.mousePosition;
                lastMousePosition += prevMousePosition.x;
                Debug.LogWarning("Pressed!");
            }
             
            if(Input.GetMouseButton(1))
            {
                var currentMousePosition : Vector2 = Input.mousePosition;
                Debug.LogWarning("Dragging!");
                Debug.LogWarning("lastYValue: " + currentMousePosition.x);
            }

            var deltaMousePosition : float = lastMousePosition - currentMousePosition.x;
            Debug.LogWarning("lastDeltaValue: " + deltaMousePosition);

            horizontalPivot.transform.Rotate (Vector3.up, deltaMousePosition * horizontalRotateSpeed);
             
            if(Input.GetMouseButtonDown(2))
            {
                if(transform.position.y >= 3)
                verticalPivot.transform.Rotate (Vector3.right, -oneFingerPosition.y * verticalRotateSpeed); 
            }
        }

Please like our page @ Redirecting...

Hopefully, this is usefull. :slight_smile:
www.cychozstudio.com

1 Like