- Home /
 
need help with script
I'm trying to script a pause menu for my game but it say unexpected token: ; and all the compiler errors have to be fixed here is the script
public class PauseMenu ; MonoBehaviour ; var menuHeight:float=500; var menuWidth:float=500; var buttonSpacing:float=25; var pauseMenu: String = ("PauseMenu"); var titleTexture:Texture2D; var customSkin:GUISkin; var customStyle:GUIStyle; function OnGUI(){ GUI.skin = customSkin; GUILayout.BeginArea(Rect(Screen.width/2-menuWidth/2,Screen.height/2-menuHeight/2,menuHeight,menuWidth),customStyle); GUILayout.Space(50); GUILayout.Label(titleTexture); GUILayout.Space(buttonSpacing); if(GUILayout.Button("Resume")){ Application.LoadLevel(mainMenu); } GUILayout.Space(buttonSpacing); if(GUILayout.Button("Exit to Desktop")){ Application.Quit(); } GUILayout.Space(buttonSpacing); GUILayout.EndArea(); }
Answer by Seregon · Jul 03, 2013 at 03:25 PM
Firstly, please format your code using the buttons at the top of the post window, it should look something like this:
 public class PauseMenu ; MonoBehaviour ; 
 var menuHeight:float=500; 
 var menuWidth:float=500; 
 var buttonSpacing:float=25; 
 var pauseMenu: String = ("PauseMenu"); 
 var titleTexture:Texture2D; 
 var customSkin:GUISkin; 
 var customStyle:GUIStyle; 
 function OnGUI(){ 
    GUI.skin = customSkin; 
    GUILayout.BeginArea(Rect(Screen.width/2-menuWidth/2,Screen.height/2-menuHeight/2,menuHeight,menuWidth),customStyle); 
    GUILayout.Space(50); GUILayout.Label(titleTexture); 
    GUILayout.Space(buttonSpacing); 
    if(GUILayout.Button("Resume"))
    { 
       Application.LoadLevel(mainMenu); 
    } 
    GUILayout.Space(buttonSpacing); 
    if(GUILayout.Button("Exit to Desktop"))
    { 
      Application.Quit(); 
    } 
    GUILayout.Space(buttonSpacing); 
    GUILayout.EndArea(); 
 }
 
               Now that it's legible, the error your getting is from the first line, where the first ; should be a :, and the second should be a {, like this:
 public class PauseMenu : MonoBehaviour {
 
              I'm Still experiencing the problem here is the code now with the fixes you told me to do here are the errors
Assets/Pause$$anonymous$$enu.js(5,3): BCE0044: unexpected char: 'v'. Assets/Pause$$anonymous$$enu.js(1,24): BCE0043: Unexpected token: :. 
and here is the code now
 public class Pause$$anonymous$$enu : $$anonymous$$onoBehaviour {  
 var menuHeight:float=500; 
 var menuWidth:float=500; 
 var buttonSpacing:float=25; 
 5.var pause$$anonymous$$enu: String = ("Pause$$anonymous$$enu"); 
 var titleTexture:Texture2D; 
 var customSkin:GUISkin; 
 var customStyle:GUIStyle; 
 function OnGUI(){ 
 10.   GUI.skin = customSkin; 
    GUILayout.BeginArea(Rect(Screen.width/2-menuWidth/2,Screen.height/2-menuHeight/2,menuHeight,menuWidth),customStyle); 
    GUILayout.Space(50); GUILayout.Label(titleTexture); 
    GUILayout.Space(buttonSpacing); 
    if(GUILayout.Button("Resume"))
 15.   { 
       Application.LoadLevel(main$$anonymous$$enu); 
    } 
    GUILayout.Space(buttonSpacing); 
    if(GUILayout.Button("Exit to Desktop"))
 20.   { 
      Application.Quit(); 
    } 
    GUILayout.Space(buttonSpacing); 
    GUILayout.EndArea(); 
 25.}
 
                 the errors are Assets/Pause$$anonymous$$enu.js(1,24): BCE0043: Unexpected token: :.
Assets/Pause$$anonymous$$enu.js(5,3): BCE0044: unexpected char: 'v'.
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Menu script not showing up like normal 1 Answer
GuiButton Going To Next Level 0 Answers
Simple Code Not Working 4 Answers
Main Menu scrpit not working 1 Answer