error Assets\mouselook.cs(21,26): error CS1002: ; expected

Im new to unity, and i was coding and i got this error: error “Assets\mouselook.cs(21,26): error CS1002: ; expected”, i cant find the problem with the script, so i dont know how to fix it, here is my code:

public class mouselook : MonoBehaviour
{
public float MouseSensivity = 100f;
public Transform playerBody;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis(“Mouse X”) * MouseSensivity * Time.deltaTime;
float mouseY = Input.GetAxis(“Mouse Y”) * MouseSensivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf,Clamp(xRotation, -90f, -90f);
transform.localRotation = Quaterion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}

use code tag when you show your script on the forum so other can read

As has been said, use code tags - this makes it easy for everyone to find the correct line and read your code properly.

Aside from that, this is most likely your problem:
Mathf,Clamp should be Mathf.Clamp

1 Like

1: you didn’t declears xRotation variables
2: is not Mathf**,Clamp you use Mathf.**Clamp
3. is not Quaterion, its Quaternion

public class mouselook : MonoBehaviour
{
    public float MouseSensivity = 100f;
    public Transform playerBody;

    private float xRotation;

    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Confined;
    }
    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("Mouse X") * MouseSensivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * MouseSensivity * Time.deltaTime;
        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, -90f);
        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }
}

And probably more… if you’re going to type in code, it has to be 100% correct.

That means:

  1. perfect spelling
  2. perfect capitalization (or lack)
  3. perfect punctuation
  4. perfect spacing (or lack of spacing)

If any of 1,2, or 3 are wrong, it won’t work. Often times if 4 is wrong, it also might not work.

How to understand compiler and other errors and even fix them yourself:

https://discussions.unity.com/t/824586/8

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

1 Like