Search Unity

Error CS1002 ; expected

Discussion in 'Scripting' started by EspanaSence, Dec 26, 2017.

  1. EspanaSence

    EspanaSence

    Joined:
    Dec 25, 2017
    Posts:
    1
    I need some help with that.

    ------------------------------------------------------------------------------------------------------------------------------------------------

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

    public class PlayerController : MonoBehaviour {

    public float speed = 2f;

    private Rigidbody2D rb2d;

    // Use this for initialization
    void Start (){
    rb2d = GetComponent<Rigidbody2D>()

    }

    // Update is called once per frame
    void Update () {

    }

    void FixedUpdate(){

    float h = Input.GetAxis("Horizontal");

    rb2d.AddForce(Vector2.right * speed * h);

    }
    }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    First of all, please use code tags. See the first post in the forum for details.

    Second of all, read the error message carefully. Generally it will contain a line number or a line number near the beginning, usually in parenthesis. This is the line number of the offending source code. And if you double-click on the error message in Unity, Unity should take you to the actual offending line, which is often very near the problem.

    In this specific case it will be the line immediately after the line where you call the GetComponent function: you have not completed the statement with a semicolon.

    Sometimes, there is a second number after the first one in parenthesis. This is the character position. It is sometimes helpful, but generally less so.