Java Script Compile error

I keep getting and error stating that I can’t add a script to my object and that I need to fix all compile errors but I don’t know how. I am a beginner at this and I know how to do most on Unity but I can’t seem to fix this problem. Any help is appreciated!

It also shows me where the error is:

function OnGUI ( ) 
{
		GUI.Box(new Rect(10,10,100,90), "Loader Menu");

		
		if(GUI.Button(new Rect(20,40,80,20), "Single Player")) {
			Application.LoadLevel(1);
		}

		if(GUI.Button(new Rect(20,70,80,20), "Multiplayer")) {
			Application.LoadLevel(2);
		}
		if(GUI.Button(new Rect(20,70,80,20), "Create Character")) {
		    Application.LoadLevel(3);
		}

how do i fix the top part for it to work? There are other parts that need to be fixed.

Posting the error you are receiving would be helpful. Unity is indicating you made an error in your code and if you look in the console it will tell you exactly what is the problemo.

here is the error

Assets/Terrain Assests/moonrise.js (21,1): BCE0044: expecting }, found ".

There’s definitely some brace mismatches in the code you posted, but it’s difficult to tell exactly what’s wrong for a number of reasons:

  • You didn’t surround the code you posted in CODE tags
  • You seem to have inserted some additional “comments” within the code, that can’t actually be in your source file

I’d suggest that you post the entire content of the offending source file, and use CODE tags so it’s easier to read in the forum.

Again, you definitely have mismatched braces in the above, but what you posted is confusing at best…

Jeff

At the very least, in the top part of your code:

function onGui ( )
}

That brace on line #2 is backwards. It should be “{” (not “}”).

However, it still seems there a mismatch in your braces (at least, by eye) even after correcting that. As I mentioned above, posting the entire file would be best. Or, at least the entire OnGUI function (if that’s where the problem is).

Jeff

*** EDIT ***

And, “onGui” should be “OnGUI”.


That is my whole script right now. And where are the mismatched braces? I fixed the one you told me to and the OnGUI. Also, I am new to this so i can’t find exactly what is wrong.

I see you modified the original post. You say you fixed the brace I pointed out, but it’s still not fixed in the code you posted. So, is that not the current script, or did you not actually change the brace?

Regarding mismatched braces… For every open brace, you need to have a matching closed brace. Even if you change the mentioned brace on line #2 to an open brace (it’s now a closed brace), it still looks like you have 1 too many closed braces in your code. By eye, it looks like you need to remove one of the last two closed braces.

Also, as I mentioned above, your “onGui” method name should be “OnGUI”.

Jeff