Mouse Look
-
SweetRevenge
- Posts: 52
- Joined: Sun Jul 04, 2010 4:53 am
Mouse Look
I was wondering if I could add something to the Mouse Look script in unity so I can turn this function on and off, so like if I press shift then it will turn off the mouse look script and I can click on a gui that just popped up, and when i'm ready to start moving again, just press shift and keep going.
-
Jediknight846
- Posts: 9
- Joined: Wed Jul 07, 2010 6:48 am
Re: Mouse Look
I am not a expert programmer, and I have no idea if this will work, and if it works then you would have to hold shift down to look, but here:
replace that part of the code with this. Hope it helps.
Code: Select all
void Update ()
{
if(Input.GetButton("Shift"))
{
if (axes == RotationAxes.MouseXAndY)
{
// Read the mouse input axis
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if (axes == RotationAxes.MouseX)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = ClampAngle (rotationY, minimumY, maximumY);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * yQuaternion;
}
}
}
Last edited by Jediknight846 on Mon Sep 27, 2010 3:03 pm, edited 1 time in total.
Re: Mouse Look
Jedi is in the right direction, but you'd want to set a variable. Remember, Update calls every few seconds, so that will only work if you are holding the button down. If you toggle a boolean you can have it set to on/off.