keefus
November 24, 2010, 10:30am
1
Hi I'm trying to add the functionality to operate mouse look only when the right mouse button is held down. I understand I have to wrap the update function in this code
if(Input.GetButton ("Fire1")){
//Current code goes here...
}
however I can't seem to get it to work. Would it be possible for someone to show me exactly how to implement the above code into the mouselook script.
Thanks
Maarten
November 24, 2010, 10:36am
2
Change the Update method of MouseLook.cs to the following:
void Update ()
{
if (Input.GetButton("Fire1"))
{
if (axes == RotationAxes.MouseXAndY)
{
float 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.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}
Instead of using Input.GetButton("Fire1"), you can use Input.GetMouseButton(1), which represents the right mouse button.
manuelv
September 12, 2012, 9:53pm
3
perfect !
thank a lot for your wisdom