- Home /
Question by
pappyneek · Apr 20, 2016 at 04:50 AM ·
c#freezerotation
How to toggle freeze transformations?
I have a script that allows my mouse to tilt stage in every direction to the point that it will flip it upside down for the game. Issue is that sometimes in the game the mouse has to continue moving further but the player runs out of real estate to keep sliding the mouse. I'm trying to introduce a freeze transformation function to this code using the letter B or something so that the whole stage can stay still while the user moves the mouse back in place and then resumes:
public enum RotationAxes { MouseXAndY = 0, MouseX = 1,MouseXAndZ = 3, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float sensitivityZ = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
public float minimumZ = -60F;
public float maximumZ = 60F;
float rotationX = 0F;
float rotationY = 0F;
float rotationZ = 0F;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (axes == RotationAxes.MouseXAndY)
{
rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY,rotationX,0);
}
else if (axes == RotationAxes.MouseXAndZ)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
rotationZ += Input.GetAxis("Mouse Y") * sensitivityZ;
rotationZ = Mathf.Clamp (rotationZ, minimumZ, maximumZ);
transform.localEulerAngles = new Vector3(rotationZ,transform.localEulerAngles.y,-rotationX);
//GetComponentInChildren
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
void LateUpdate()
{
}
}
I have very little to no idea what I'm doing and honestly I'm surprised I'm even this far with the code. Any ideas?
Comment