- Home /
I got a bunch of errors that make no sense to me. Help.
This is for a pause menu and I got a lot of unreasonable errors. I am also trying to get a foothold in Java scripting. These are the errors.
Assets/Scripts/PauseMenu.js(1,24): BCE0043: Unexpected token: :.
Assets/Scripts/PauseMenu.js(3,9): BCE0043: Unexpected token: public.
Assets/Scripts/PauseMenu.js(3,15): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/PauseMenu.js(3,23): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/PauseMenu.js(5,17): BCE0043: Unexpected token: Rect.
Assets/Scripts/PauseMenu.js(6,17): BCE0043: Unexpected token: boolean.
Assets/Scripts/PauseMenu.js(6,39): BCE0043: Unexpected token: ,.
Assets/Scripts/PauseMenu.js(6,40): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/PauseMenu.js(8,17): BCE0043: Unexpected token: void.
Assets/Scripts/PauseMenu.js(8,29): UCE0001: ';' expected. Insert a semicolon at the end.
Assets/Scripts/PauseMenu.js(10,28): BCE0044: expecting :, found '='.
This is the code I scripted. Thanks for the help.
public class pauseMenu : MonoBehavior;
{
public GUISkin myskin;
private Rect windowRect;
pricate bool paused = false, waited = true;
pricate void Start()
{
windowRect = new Rect(Screen.width/2-100, Screen.height/2-100,200,200);
}
private void waiting()
{
waited = true;
}
private void Update()
{
if (waited)
if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
{
if (paused)
paused = false;
else
paused = true;
waited = false;
Invoke("waiting",0.3f);
}
if(paused)
Time.timeScale =0;
else
Time.timeScale =1;
}
private void OnGUI()
{
if (paused)
windowRect = GUI.Window(0,windowRect,windowFunc, "Pause Menu");
}
private void windowFunc(int id)
{
if(GUILayout.Button("Resume"))
{
paused = false;
}
GUILayout.BeginHorizontal();
if(GUILayout.Button("Options"))
{}
if(GUILayer.Button("Main Menu"))
{}
GUILayout.EndHorizontal();
}
}
Answer by Jamora · Jul 29, 2013 at 10:42 PM
Remove the semicolon ( ; ) from after MonoBehaviour on the first line. Class declaration is not a statement, so it should not have a semicolon, which indicates a statement has ended. Otherwise this code looks like it would compile.
You need to read the compiler errors. You still have typos in there. Hint: two typos in access modifiers, one in a unity class and one case where you're using a wrong class to show a button.
I'm sorry, but I won't give you the working script. I know for a fact if I do, you will not have learned anything. So if you're serious about making your game, you need to learn how to read compiler errors, and fix the problems.
The thing you need to do with compiler errors, is fix the topmost one, then see if it compiles. Repeat for as long as there are errors.
I'm telling you, you have three typos in your code and you're trying to call a function from a class that doesn't have it. The compiler will tell you the location of each of these.
I figured out the problem. I was coding in C# inside of a .js I feel dumb. Thanks for the help.
Answer by tw1st3d · Jul 31, 2013 at 12:24 AM
using UnityEngine;
using System.Collections;
using System;
public class pauseMenu : MonoBehavior
{
public GUISkin myskin;
private Rect windowRect;
private bool paused = false, waited = true;
private void Start()
{
windowRect = new Rect(Screen.width/2-100, Screen.height/2-100,200,200);
}
private void waiting()
{
waited = true;
}
private void Update()
{
if (waited)
{
if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
{
if (paused)
paused = false;
else
{
paused = true;
waited = false;
Invoke("waiting",0.3f);
}
}
if(paused)
Time.timeScale =0;
else
Time.timeScale =1;
}
}
private void OnGUI()
{
if (paused)
windowRect = GUI.Window(0,windowRect,windowFunc, "Pause Menu");
}
private void windowFunc(int id)
{
if(GUILayout.Button("Resume"))
paused = false;
GUILayout.BeginHorizontal();
if(GUILayout.Button("Options"))
{
}
if(GUILayer.Button("Main Menu"))
{
}
GUILayout.EndHorizontal();
}
}
There was a little confusing on one of your if statements and where it ended, so take a look at lines 23-42 and make sure I got that right. Other than that, a few spelling errors, and missing brackets. This should compile.
It was actually coded to be in a C# file not a java script. Thanks for the help though.
Your answer
Follow this Question
Related Questions
Pause menu scripting help? 1 Answer
Hold the esc button for a pause menu 1 Answer
Pause Menu Text Not Rendering 0 Answers
Pause Menu Problem 1 Answer
Bool wont change... #C 1 Answer