Multiple errors for player controller

For some reason, this gives multiple errors:

Assets\Scripts\PlayerMovement.cs(8,6): error CS1513: } expected

Assets\Scripts\PlayerMovement.cs(10,12): error CS1519: Invalid token ‘=’ in class, struct, or interface member declaration

Assets\Scripts\PlayerMovement.cs(10,39): error CS1519: Invalid token ‘(’ in class, struct, or interface member declaration

Assets\Scripts\PlayerMovement.cs(10,40): error CS8124: Tuple must contain at least two elements.

Assets\Scripts\PlayerMovement.cs(24,1): error CS1022: Type or namespace definition, or end-of-file expected

Here’s the code I took from here:

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    Rigidbody2D rb;

    void Start()
    {
        public float speed;
        rb = GetComponent<Rigidbody2D>()
    }

    void Update()
    {
        Move();
    }
   
    void Move()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float moveBy = x * speed;
        rb.velocity = new Vector2(moveBy, rb.velocity.y);
    }
}

Go back to the tutorial and carefully review the step where they insert the public float speed; line.

With software engineering it has to be (pretty much) 100% correct, not “Sorta like.” :slight_smile: This includes punctuation, capitalization, spelling, and ordering.

1 Like

Based on your error message you have a prob lem with the filename too. Unity expects the filename to match the class name. In your case you have “PlayerMovement.cs” but your class is called “PlayerController”. Your script will not work properly with that mismatch. You need either:

Filename: “PlayerMovement.cs”, Class Name: “PlayerMovement”
or
Filename: “PlayerController.cs”, Class Name: “PlayerController”

1 Like

Fixed it. The main issue was the public float speed; being in the Start() void rather right up top with rb = GetComponent<Rigidbody2D>();.[

1 Like