Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I need help, my unity says there is a CS1002 error but i cant find it

Discussion in 'Scripting' started by MilkBonerDani, Apr 23, 2022.

  1. MilkBonerDani

    MilkBonerDani

    Joined:
    Apr 23, 2022
    Posts:
    5
    Code:

    public class PlayerMovment : MonoBehaviour

    {
    Rigidbody rb;
    [SerializeField] float movmentSpeed = 5f;
    [SerializeField] float jumpForce = 5f;

    [SerializeField] Transform groundCheck;

    // Start is called before the first frame update
    void Start()

    {
    rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    rb.velocity = new Vector3(horizontalInput * movmentSpeed, rb.velocity.y, verticalInput * movmentSpeed);

    if (Input.GetButtonDown("Jump"))
    {
    rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
    }
    }

    bool IsGrounded()
    {
    retern true;
    }
    }
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
    Use code tags! Don't expect us to read a wall of text.
    Post the error message, copy and paste from the Unity console. It's rare anybody remembers error codes.

    Otherwise, the error code will point you to the error. You'll probably also get red squiggles where the error is.

    It's possible this is where your error is.

    upload_2022-4-23_16-50-0.png

    Remember, typos will prevent your code from working!
     
  3. MilkBonerDani

    MilkBonerDani

    Joined:
    Apr 23, 2022
    Posts:
    5
    error is: Assets\PlayerMovment.cs(33,16): error CS1002: ; expected
     
  4. MilkBonerDani

    MilkBonerDani

    Joined:
    Apr 23, 2022
    Posts:
    5
    also has no red squiggles
     
  5. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    It's "return", not "retern". The error tells you to look at line 33.

    If you have no squiggles, you didn't configure Unity and visual studio correctly.
     
  6. MilkBonerDani

    MilkBonerDani

    Joined:
    Apr 23, 2022
    Posts:
    5
    when I put return theres more errors tho
     
  7. beinzheans

    beinzheans

    Joined:
    Dec 16, 2021
    Posts:
    12
    then fix the extra errors? one thing i realised was you used


    Code (CSharp):
    1. bool isGrounded()
    2. {
    3. return true;
    4. }
    which could be another error
     
  8. MilkBonerDani

    MilkBonerDani

    Joined:
    Apr 23, 2022
    Posts:
    5
    might be because im not done with it yet
     
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    This is simply your own typographic mistake and you can fix it all by yourself.

    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.

    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.

    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.