Hi guys
I’m trying to understand what the RotationAxes.MouseXAndY is in a MouseLook script. I find the rotationAxes is initialised as RotationAxes.MouseXAndY, and never be updated again. However, how does it work if the rotationAxes’ value never changed ?
This is the script,
public class MouseLook : MonoBehaviour
{
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY; // get initialised here
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
public float mouseX;
public float mouseY;
void Update()
{
if (networkView.isMine)
{
if (Screen.lockCursor)
{
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
}
else
{
mouseX = 0;
mouseY = 0;
}
if (axes == RotationAxes.MouseXAndY) // Check in the if but the value never change....
{
float rotationX = transform.localEulerAngles.y + mouseX * sensitivityX;
rotationY += mouseY * sensitivityY;
rotationY = Mathf.Clamp(-rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, mouseX * sensitivityX, 0);
}
else
{
rotationY += mouseY * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
else
{
this.enabled = false;
}
}
void Start()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
if (!networkView.isMine) this.enabled = false;
}
}