X-Axis rotation quirk
I have a script that rotates an object whilst a button is pressed. The rotation plane depends on which axis is selected in the Dropdown menu. The script works mostly fine for the Y and Z axis, but has unexpected behaviour on the X-Axis.
When holding in the left rotate button, the volume will rotate to -90 and get 'stuck'. I then hold in the right rotate button and it doesn't go further than 90 before getting stuck again. What's even weirder is that quite often after getting stuck in a particular direction and switching to the alternate direction, instead of the volume going back the other way, it continues in the direction it was going had it not gotten stuck in the first place. This causes the left and right rotation buttons to be swapped around.
Here is the code with all the main operations.
public void Update()
{
axis = axisDropdown.value;
Vector3 originalRot = transform.eulerAngles;
if (buttonHeld)
{
if (rotateRight)
{
if (axis == 0)
{
originalRot.x += 1;
transform.rotation = Quaternion.Euler(originalRot);
}
else if (axis == 1)
{
originalRot.y += 1;
transform.rotation = Quaternion.Euler(originalRot);
}
else if (axis == 2)
{
originalRot.z += 1;
transform.rotation = Quaternion.Euler(originalRot);
}
else
{
print("Error: Selected axis option is invalid");
}
}
else
{
if (axis == 0)
{
originalRot.x -= 1;
transform.rotation = Quaternion.Euler(originalRot);
}
else if (axis == 1)
{
originalRot.y -= 1;
transform.rotation = Quaternion.Euler(originalRot);
}
else if (axis == 2)
{
originalRot.z -= 1;
transform.rotation = Quaternion.Euler(originalRot);
}
else
{
print("Error: Selected axis option is invalid");
}
}
}
}
I have read of other similar problems to mine, but they all seem to be slightly different so any help would be appreciated.