- Home /
(10,47): BCE0044: expecting :, found '='.
I'm working on setting up my GUI for my project, and so far everything is going pretty well. However when I tried adding my if statements for my boolean variable TogglleMenu I recieve the error expecting :, found '='. on the 10th line. Any help figuring this problem out would be nice as I'm fairly new to Javascript.
var bannerskin : GUISkin; var ToggleMenu : boolean = false; function Update() { if(Input.GetKeyDown(KeyCode.Escape)) PauseGame(); } static function PauseGame() { if(!ToggleMenu) { { Time.timeScale=0; AudioListener.pause = true; ToggleMenu=true; } else { Time.timeScale=1; AudioListener.pause = false; ToggleMenu=false; } } } function OnGUI() { GUI.skin = bannerskin; //switch to my bannerskin if(Time.time<=10) { GUI.Box(Rect (Screen.width/4,0,Screen.width/2,Screen.height/5), ""); } GUI.skin = null; //switch to default skin if(!ToggleMenu) //if ToggleMenu = true execute follwing, Application.Exit, Prompt Level Select GUI, or unpause game. { if(GUI.Button(Rect (Screen.width/2,Screen.height/2,Screen.width/6,Screen.height/12), "Exit Program")){ Application.Exit; } if(GUI.Button(Rect (Screen.width/2,(Screen.height/2)+(Screen.height/12),Screen.width/6,Screen.height/12), "Level Select")){ //Next Level Select Menu code goes here } if(GUI.Button(Rect (Screen.width/2,(Screen.height/2)+(Screen.height/12)+(Screen.height/12),Screen.width/6,Screen.height/12), "Back To Game")){ Time.timeScale=1; AudioListener.pause = false; ToggleMenu=false; } }
}
Answer by Bunny83 · May 03, 2011 at 10:25 PM
If i fix the two errors we mentioned
above
below the only thing that is still wrong is that there's no Exit function in Application. It's called Application.Quit() and you have to put brakets behind it.
Here's the fully working script:
var bannerskin : GUISkin; static var ToggleMenu : boolean = false;
function Update() { if(Input.GetKeyDown(KeyCode.Escape)) PauseGame(); }
static function PauseGame() { if(!ToggleMenu) { Time.timeScale=0; AudioListener.pause = true; ToggleMenu=true; } else { Time.timeScale=1; AudioListener.pause = false; ToggleMenu=false; } }
function OnGUI() { GUI.skin = bannerskin; //switch to my bannerskin if(Time.time<=10) { GUI.Box(Rect (Screen.width/4,0,Screen.width/2,Screen.height/5), ""); } GUI.skin = null; //switch to default skin if(!ToggleMenu) //if ToggleMenu = true execute follwing, Application.Quit, Prompt Level Select GUI, or unpause game. { if(GUI.Button(Rect (Screen.width/2,Screen.height/2,Screen.width/6,Screen.height/12), "Exit Program")){ Application.Quit(); } if(GUI.Button(Rect (Screen.width/2,(Screen.height/2)+(Screen.height/12),Screen.width/6,Screen.height/12), "Level Select")){ //Next Level Select Menu code goes here } if(GUI.Button(Rect (Screen.width/2,(Screen.height/2)+(Screen.height/12)+(Screen.height/12),Screen.width/6,Screen.height/12), "Back To Game")){ Time.timeScale=1; AudioListener.pause = false; ToggleMenu=false; } } }
Thank's a lot. That solved my problem I was having. (Btw, I just was going off the top of my head for the Application.quit() command, but thanks for bringing it up anyways).
Answer by Bryan 4 · May 03, 2011 at 09:27 PM
Original code:
if(!ToggleMenu)
{
{
Time.timeScale=0;
AudioListener.pause = true;
ToggleMenu=true;
}
else
{
Time.timeScale=1;
AudioListener.pause = false;
ToggleMenu=false;
}
}
your brackets are mismatched. should be
if(!ToggleMenu)
{
Time.timeScale = 0;
AudioListener.pause = true;
ToggleMenu = true;
}
else
{
Time.timeScale = 1;
AudioListener.pause = false;
ToggleMenu = false;
}
In addition you have to make Toggle$$anonymous$$enu static in order to use it inside a static function.
Tried switching this out with what I had, and it gave me the following errors:
Assets/Imported from other project/Scripts/other/NewBehaviourScript.js(23,10): BCE0044: expecting (, found 'OnGUI'. Assets/Imported from other project/Scripts/other/NewBehaviourScript.js(23,17): UCE0001: ';' expected. Insert a semicolon at the end. Assets/Imported from other project/Scripts/other/NewBehaviourScript.js(25,18): BCE0044: expecting :, found '='.
Your answer
Follow this Question
Related Questions
BCE0044 error: OnControllerColliderHit 2 Answers
BCE0044: expecting :, found '=' 2 Answers
script error GUI super simple code 3 Answers
SwipeControl package error in unity iPhone 1.7 1 Answer
error help 2 Answers