Hello guys i have a problem in my script i am making a cube rolling with arrow keys in unity …but when i change it in drag system (mobile input or click drag) it is not working …i want it to drag in X and Y axis …i am not familiar with unity…check out my error part…
void Update () {
float x = 0;
float y = 0;
x = Input.GetAxisRaw ("Horizontal");
if (x == 0) {
y = Input.GetAxisRaw ("Vertical");
}
if ((x != 0 || y != 0) && !isRotate) {
directionX = y;
directionZ = x;
startPos = transform.position;
fromRotation = transform.rotation;
transform.Rotate (directionZ * 90, 0, directionX * 90, Space.World);
toRotation = transform.rotation;
transform.rotation = fromRotation;
rotationTime = 0;
isRotate = true;
}
Use Log to check if both “Input.GetAxisRaw (“Horizontal”);” and “Input.GetAxisRaw (“Vertical”);” always gives you “0”.
On a mobile device, tilting your phone changes these values. On the editor, the arrow keys changes the values.
If both are zero, try and use “Input.acceleration.x” instead of “Input.GetAxisRaw (“Horizontal”);” and “Input.acceleration.y” instead of “Input.GetAxisRaw (“Vertical”);”. Note if it works.
I hope you are changing the value of “isRotate” at some point after setting it to “true”. Otherwise you wouldn’t be able to see any changes, as the values are applied only once.
I have added the full code. You can modify it as you want.