Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why does it say "CS1002 ; Expected"?

Discussion in 'Documentation' started by Kyllekongen, Jan 16, 2021.

  1. Kyllekongen

    Kyllekongen

    Joined:
    Jan 16, 2021
    Posts:
    2
    So i'm new to coding and would like some help for my first script. It says that it expected a ";" but i don't know where the problem is. Can anybody please help me?

    This is my script

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

    public class Movement : MonoBehaviour
    {
    Rigidbody rb;
    // Start is called before the first frame update
    void Start()
    {
    ; rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
    ; Rigidbody OnMouseDown Velocity = Vector3.forward;
    }
    }
     
  2. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,662
    Food for thought:
    1. When posting code in the forum, please use Code Tags to make it more readable - here's how:
      https://forum.unity.com/threads/using-code-tags-properly.143875/
    2. While getting an error, you can actually see on which Line the error happened. Check the
      Console Window
      (top menu: Window > General > Console) - the text is usually something like this: [XT:IM:EX] <the script that throws the error>(LINE NUMBER, ANOTHER NUMBER).

    Now, onto your issue: Those semicolons at the beginning of each line are wrong. Remove them and the script should work fine. Actually, forget that part.
    .
     
    Last edited: Jan 17, 2021
  3. I'm not too sure about that line though, even if you take away the semicolon at the beginning. I'm also not sure what they wanted to say with this line though.

    And obviously, what is this doing in the Documentation forum?
     
  4. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,662
    Yeah, obviously, that
    Rigidbody OnMouseDown Velocity = Vector3.forward;
    line is total bollocks o_O I- probably shouldn't visit this forum when I'm half-awake...

    As for why it's in the Documentation forum? No idea. Do we still have mods around here?

    @OP Take a look at the Documentation pages for
    OnMouseDown
    and
    Rigidbody.velocity
    .
     
    Last edited: Jan 17, 2021
  5. Kyllekongen

    Kyllekongen

    Joined:
    Jan 16, 2021
    Posts:
    2
    And obviously, what is this doing in the Documentation forum?[/QUOTE]

    I don't know where to get help with issues yet, sorry.
     
  6. Deleted User

    Deleted User

    Guest

    This code cannot work without throwing errors; Only put semicolons at the end of lines, not at the beginning with a space. Like Mairi said, read the doc.
    This is works best for simple usages like that:
    Code (CSharp):
    1. using UnityEngine;
    2. public class Movement : MonoBehaviour
    3. {
    4.     Rigidbody rb;
    5.    
    6.     void Start()
    7.     {
    8.         rb = GetComponent<Rigidbody>();
    9.     }
    10.    
    11.     void Update()
    12.     {
    13.         if (Input.GetMouseButtonDown(0))
    14.             rb.velocity = Vector3.forward;
    15.         else
    16.             rb.velocity = Vector3.zero;
    17.     }
    18. }