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

Question Error CS1002

Discussion in 'Scripting' started by PflaumeJJ, Jul 18, 2023.

  1. PflaumeJJ

    PflaumeJJ

    Joined:
    Jul 17, 2023
    Posts:
    1
    Hello can anyone tell me whats wrong with my code?



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class movement : MonoBehaviour
    {
    Rigidbody rb;
    float speed;

    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody>()
    speed = 10.0f;
    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKey(KeyCode.RightArrow))
    {
    rb.velocity = new Vector3(rb.velocity.x + 0.03f, rb.velocity.y, rb.velocity.z);;
    }
    }
    }
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    You should be telling us that information by providing something more useful than just an error code which, so you know, is fairly meaningless for the most part.

    The error you get will tell you both the line and the column number and a description of the error.

    Also, please post use code-tags and not plain text so the line number is shown.

    Thanks.
     
  3. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    510
    The semicolon at the end of line 13 ran away to go live with the semicolon at the end of line 22.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    You're just making typing mistakes. Stop doing that. When you make typos, go fix them. 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?

    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.
     
  5. PercyHinton

    PercyHinton

    Joined:
    Jul 19, 2023
    Posts:
    1
    Hii, Missing semicolon after "rb = GetComponent<Rigidbody>()".