- Home /
Duplicate Question
MouseLook Disable function
I am trying to disable the MouseLook when the left mouse button is clicked. However the code I have put in does not do that and I am not quite sure why. Any help would be greatly appreciated. Here is the code:`
class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
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;
void Update ()
{
if (Input.GetMouseButtonDown (0) = false) {
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);
}
}else if (Input.GetMouseButtonDown (0) = true) {
}
}
void Start ()
{
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>())
GetComponent<Rigidbody>().freezeRotation = true;
}
} `
Please include any errors you receive when posting questions.
In line 17, your if statement has a syntax error. = is an assignment operator, == is a comparison operator.
Also, it will only disable mouselook during the frame in which L$$anonymous$$B was clicked, which is probably not what you want. Use Get$$anonymous$$ouseButton() ins$$anonymous$$d.
To achieve your goal, you could replace your whole if(){} block with
if (Input.Get$$anonymous$$ouseButton(0)) return;
Answer by robertbu · Nov 03, 2014 at 11:58 PM
You are using '=' instead of '==' on line 17. Plus using '!' is more professional:
if (!Input.GetMouseButtonDown (0)) {
Follow this Question
Related Questions
C# scriping help 0 Answers
MonoDevelop 4.0.1 code completion doesn't work 2 Answers
C# Script is affecting multiple GameObjects but I would like it to only affect one of them... 1 Answer
Inventory system Help 2 Answers
Float and Double conversion issues 0 Answers