I'm trying to create a mobile joystick using this free package from Unity. Here is the code for rotation which seems to be working fine. I just want to clamp the rotation to +90 or -90 degress. I have tried using the mathf.clamp function but the plane(player) completes a full rotation.
public Joystick joystick;
float rotateVertical;
float rotateHorizontal;
float minClamp = -90.0f;
float maxClamp = 90f;
void Update()
{
rotateVertical = Mathf.Clamp(joystick.Vertical * 1f, minClamp, maxClamp);
rotateHorizontal = Mathf.Clamp(joystick.Horizontal * -1f, minClamp, maxClamp);
transform.Rotate(rotateVertical, 0, rotateHorizontal);
}
If I change the value of minClamp to 0, then the plane doesn't rotate on the negative x axis but is still able to complete a full rotation on the positive x axis. Can someone please help me?