Error expected }

Hi uhm so Im new to unity and I finally figured out on how to make a Player controller with a bit help from Brackeys. So it tells me that I should put “}” somewhere so I wanted to ask if anyone can help me.

heres the script:
using UnityEngine;

public class PlayerMovement : MonoBehaviour

public Rigidbody rb;

public float ForwardForce = 500f;
public float SidewardsForce = 500f;

// Start is called before the first frame update
void Start()
{

}

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

if (Input.GetKey(“w”)) ;
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);

}
}

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

How to use code tags: Using code tags properly

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

How to report your problem productively in the Unity3D forums:

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

2 Likes

you need a opening bracket under the line with

public class PlayerMovement : MonoBehaviour

and a closing bracket at the end of your code.

and you have to remove semicolon after your if statement.

Please use code tags for your next post to make it more readable.

2 Likes

Get rid of the semicolon from this line: if (Input.GetKey("w")) ; it should just be if (Input.GetKey("w"))

2 Likes

Ok I will do It next time can you maybe help me with this problem?

As the folks above point out, 100% of spelling, capitalization and punctuation must be PERFECT for your program to work. It’s not optional.

1 Like

Are you using an IDE? The IDE should have told you exactly what the problem was right away. It would put a red squiggly line right under that unexpected semi-colon or missing opening bracket. Or maybe you are using an IDE and it told you that it “expects a ‘}’” character? If so, keep in mind that the message an IDE or Unity might post is not always 100% explicit. It might not say, “A semi-colon is invalid here”. Instead, it might say, "I expected an end-bracket ‘}’ character before the end-of-statement, but didn’t see it. This is because the compiler sees that you have an “if(something)” statement, and it expects to see brackets following it, but you also put a semi-colon, which is interpreted as “this is the end of the statement”. As a result, it says "Well, I went to the end of the statement and never saw any of the expected brackets, so I will tell the person that I expected a “}”, and didn’t get it. Although, this might also be specifically because you were missing an open bracket in the class initializer.

ok

whats IDE?

IDE = Integrated Development Environment

for example Visual Studio is the IDE that is mostly used for coding in C#.

ok I quess I have it

It sounds like you are new to programming, and not just Unity. You should take some courses on coding before you begin working on a video game. At least in my opinion, it is easier to make some simple apps and learn C# than learning to program at the same time that you’re jumping into video game development. I’ve worked on web apps, basic native apps, and video games, and games are the least forgiving to a noobie (unless you are using visual scripting like Playmaker).

If you don’t know what an IDE is, and don’t know how to interpret errors like this yet, it may behoove you to start small and get your feet wet doing something more forgiving first. And that doesn’t mean it will take long. You could spend a month learning, and then be much more equipped to breeze through making your first game.

So uhm yeah Im only new to C# I already made a few games in Roblox studio so in Lua

Sorry. I guess I thought that was the case because you didn’t know what an IDE was and didn’t know how to debug this. My bad. It might still help to take a class on C# because Lua is fairly different. But either way, good luck with your game!

Still im bad but thank you for your help Im just not that good when it comes to programming and this is thankfully to all of you who helped me my first working script ^^

1 Like

also unity is now a lot more fun before I just dont liked it but now its pretty cool and I will (hopefully) keep geting better and not just me I hope that someday alot of games made by Indie Devs. will be very popular