Type or namespace definition, or end-of-file expected

Im new to unity and C# im also following a brackeys tutorial on how to do controller inputs, the code itself im assuming is fine, but im getting this stupid error, does anyone know what it means and how to fix it?

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

public class P2Script : MonoBehaviour{}
public Rigidbody rb2;

{

    P2Control controls;

    void Awake()
    {
    controls = new P2Control();

    controls.Gameplay.Left.performed += ctx => Left();
    }

    void Left()
    {
       rb2.AddForce(-3, 0, 0);
    }

    void OnEnable()
    {
       controls.Gameplay.Enable();
    }

    void OnDisable()
    {
       controls.Gameplay.Disable();
    }


}

Thanks.

Your class starts and ends in this line, due to opening and closing parentheses:

public class P2Script : MonoBehaviour{}

Thus the other parts of your script do not belong to any type, which is invalid.

It seems you already have the actual parentheses for the class in place (opening in line 9, closing in line 36).
Remove the parentheses in line 6 and move line 7 into the type’s scope, e.g. line 10.

2 Likes

Yea but now im having some issue where if it forces me to add arrow parentheses otherwise it wont let me play my game.

How to report problems productively in the Unity3D forums:

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

@Suddoha pointed out fundamental syntax construct errors in your script. If you believe you fixed them, repost the updated script with code tags.

Help us to help you.

i am getting the same problem and i am new to unity

Please don’t necro-post to old threads for your own typos. Instead, just go fix your own typos. Here’s how:

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.

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.

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.