- Home /
Question by
jeremydulong · Apr 07, 2019 at 11:52 PM ·
rotationmobilemousegetaxis
GetAxis difference between mobile and mouse
I'm using the simple script below to rotate an object in 3D world space. It does work correctly while dragging on mobile and in the unity Game view. And when clicking the mouse around the screen the object does not rotate until you start dragging the mouse around. The issue is that simply tapping the screen on mobile causes the cube to instantly rotate, and then the dragging works. Why is this happening on mobile only, and does anyone have suggestions to fix the issue?
public class RotateDemo: MonoBehaviour
{
public float rotSpeed = 100;
void Update()
{
if (Input.GetMouseButton(0))
{
float rotX = Input.GetAxis("Mouse X") * rotSpeed * Mathf.Deg2Rad;
float rotY = Input.GetAxis("Mouse Y") * rotSpeed * Mathf.Deg2Rad;
transform.Rotate(Vector3.forward, -rotX, Space.World);
transform.Rotate(Vector3.right, rotY, Space.World);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Clockwise or counter-clockwise motion 1 Answer
How to rotate an object around a fixed point by 1 Answer
Rotate a crank with the mouse 0 Answers
Character Not Rotating 0 Answers