cs1002 error how do i fix?

i am very new to unity2d and i was watching tutorials on how to make a scrolling background and i copied this code and for some reason i get error cs1002 and i dont know what the problem is iv ben trying to find out for the past 2 hours i cant do it so maybe someone can help me.

Here is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class backgroundscroller : MonoBehaviour
{
private BoxCollider2D boxcollider;
private rigidbody2D rb;
private float width;
private float speed = -3f;
// use this for initialization
void Start()
{
boxcollider = getcomponent();
rb = getcomponent();
width = boxcollider.size.x
rb.velocity = new vector2(speed, 0)
}
// Update is called once per frame
void Update()
{
if (transform.position.x<-width)
{
reposition();
}
}
private void reposition()
{
vector2 vector = new vector2(width * 2f, 0);
transform.position = (vector2)transform.position + vector;
}
}

CS1002 is a missing semicolon.
Please use code tags when showing code as its very hard to read otherwise Using code tags properly

You have a few problems with your script.
They are easy to spot if you put them into a code editor such as Visual Studio
The red lines indicate potential problems. Mouse over them for more details.
6921182--811946--upload_2021-3-10_16-41-56.png

Code is case sensitive so you need to make sure to capitalize the classes, for example rigibody2D should be Rigidbody2D.

getcomponent should be GetComponent

You are also missing 2 semicolons,
1 after each line here
width = boxcollider.size.x
rb.velocity = new vector2(speed, 0)

This should be the end result

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

    public class backgroundscroller : MonoBehaviour
    {
        private BoxCollider2D boxcollider;
        private Rigidbody2D rb;
        private float width;
        private float speed = -3f;
        // use this for initialization
        void Start()
        {
            boxcollider = GetComponent<BoxCollider2D>();
            rb = GetComponent<Rigidbody2D>();
            width = boxcollider.size.x;
            rb.velocity = new Vector2(speed, 0);
        }
        // Update is called once per frame
        void Update()
        {
            if (transform.position.x < -width)
            {
                reposition();
            }
        }
        private void reposition()
        {
            Vector2 vector = new Vector2(width * 2f, 0);
            transform.position = (Vector2)transform.position + vector;
        }
    }
2 Likes

NOBODY remembers error codes. Nobody.

How to understand compiler and other errors and even fix them yourself:

https://discussions.unity.com/t/824586/8

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

2 Likes