Ingame menu problems

Hey, I’m using an ingame menu script that is supposed to have this actions - Resume,Quit,Restart,Main Menu… Resume and Quit works fine but I can’t get Restart and Main Menu to work in standalone pc format. Anyone know why these commands won’t work in standalone pc format?

Here is the script:

var guiSkin: GUISkin;
var nativeVerticalResolution = 700.0;
var isPaused : boolean = false;
Screen.showCursor = false;

function Update()
{
     if(Input.GetKeyDown("escape") && !isPaused)
   {
      print("Paused");
      Time.timeScale = 0.0;
      isPaused = true;
      Screen.showCursor = true;
   }
   else if(Input.GetKeyDown("escape") && isPaused)
   {
      print("Unpaused");
      Time.timeScale = 1.0;
      isPaused = false;    
     Screen.showCursor = false;
   } 
}
function OnGUI ()
{
    // Set up gui skin
    GUI.skin = guiSkin;
    // Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect). The next line makes sure it rescales nicely to other resolutions.
    GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1)); 
    if(isPaused)
    {
      // RenderSettings.fogDensity = 1;
      if(GUI.Button (Rect((Screen.width)/3,540,200,75), "Quit", "button2"))
      {
         print("Quit!");
         Application.Quit();
      }
      if(GUI.Button (Rect((Screen.width)/3,440,270,75), "Restart", "button2"))
      {
         print("Restart");
         Application.loadedLevel("");
         Time.timeScale = 1.0;
         isPaused = false;
      }
	  if(GUI.Button (Rect((Screen.width)/3,340,310,80), "Main Menu", "button2"))
      {
         print("Main Menu");
         Application.LoadLevel("0");
      }
      if(GUI.Button (Rect((Screen.width)/3,240,270,75), "Continue", "button2"))
      {
         print("Continue");
         Time.timeScale = 1.0;
         isPaused = false;
		 Screen.showCursor = false;
      }
   } 
}
@script AddComponentMenu ("GUI/Pause GUI")

I think your Application.LoadLevel() functions are incorrect.

For the Main Menu button, you are passing in a “0” which is a string and not an integer … remove the quotes. Try this line:

Application.LoadLevel(0);

for the Reset button, try adding an actual level name into your LoadLevel(“”); function.

Application.LoadLevel("put level name here");

Hope that helps!

Application.loadedLevel() is not a method but a variable that contains the index of the last loaded level. It doesn’t load anything.

Application.LoadLevel() is a method which loads a level based on the parameter that you pass to it. In the Main Menu block of your code, you're passing "0" to Application.LoadLevel(), which is a string and not an integer.

As such, Application.LoadLevel() will try to locate a level named 0, which it will obviously not find unless you actually gave your level the name 0. What you should do is pass the integer 0 to the method and not the string "0".

As for the Restart block of your code, you are correct in assuming that Application.loadedLevel is involved in getting the level to restart but incorrect in your usage of it. It is not a method to be invoked but rather a variable to get the value of. After obtaining the value, it should then be passed to the method Application.LoadLevel().

Long story short, change

Application.loadedLevel("") -> Application.LoadLevel(Application.loadedLevel)

And channge

Application.LoadLevel("0") -> Application.LoadLevel(0)