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

Assets\Scripts\Player.cs(16,43): error CS1002: ; expected

Discussion in 'Getting Started' started by banananana1234, Oct 1, 2023.

  1. banananana1234

    banananana1234

    Joined:
    Sep 30, 2023
    Posts:
    1
    I am trying to get a simple movement system set up but I keep getting the error Assets\Scrips\Player.cs(16,43): error CS1002: ; expected It wont let me enter play mode because all compiler errors must be fixed Please help. :(
    Ps this is just for the cursor movement)


    using UnityEngine;


    public class Player : MonoBehavior
    {
    Vector2 look;


    void start()
    {

    }

    void Update()
    {
    look.x += Input.GetAxis("Mouse X")
    look.y += Input.GetAxis("Mouse Y")
    Debug.Log(look);
    }
    }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,281
    You're just making typing mistakes. I can see THREE (3) in the code above: two missing semicolons and a mis-capitalized Unity MonoBehaviour method.

    You must have ZERO mistakes.

    You can fix your own typing mistakes. Here's how:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    In the future, when you have an ACTUAL problem and need to post code, ALWAYS USE CODE TAGS:

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

    - Do not TALK about code without posting it.
    - Do NOT post unformatted code.
    - Do NOT retype code. Use copy/paste properly using code tags.
    - Do NOT post screenshots of code.
    - Do NOT post photographs of code.
    - ONLY post the relevant code, and then refer to it in your discussion.
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,372
    1) use code tags:
    https://forum.unity.com/threads/using-code-tags-properly.143875/

    2) read your error, it says a line number (16) and what is expected (you're missing a semi-colon)

    Code (csharp):
    1. look.x += Input.GetAxis("Mouse X")
    No semi-colon.

    Same for the next line.

    Start is also mispelled as 'start', but that won't cause it to not compile. That'll just make it not get called by Unity.
     
    Ryiah and Bunny83 like this.
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,797