Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Scripting' started by Manuovni, Mar 25, 2021.

  1. Manuovni

    Manuovni

    Joined:
    Mar 25, 2021
    Posts:
    1
    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);
    }
    }
     
  2. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
  3. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    480
    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
     
    Putcho likes this.
  4. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246

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

    Code (CSharp):
    1. public class mouselook : MonoBehaviour
    2. {
    3.     public float MouseSensivity = 100f;
    4.     public Transform playerBody;
    5.  
    6.     private float xRotation;
    7.  
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         Cursor.lockState = CursorLockMode.Confined;
    12.     }
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         float mouseX = Input.GetAxis("Mouse X") * MouseSensivity * Time.deltaTime;
    17.         float mouseY = Input.GetAxis("Mouse Y") * MouseSensivity * Time.deltaTime;
    18.         xRotation -= mouseY;
    19.         xRotation = Mathf.Clamp(xRotation, -90f, -90f);
    20.         transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    21.         playerBody.Rotate(Vector3.up * mouseX);
    22.     }
    23. }
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    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://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

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

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
    Putcho likes this.