x


load button in main menu

hello, im trying to make a load game button in my game, but there is allways errors. i can save my game and load my game when im playing but i want to load the game from the main menu to. please help me. This is my script:

var mainMenuSceneName : String;
var pauseMenuFont : Font;

private var showGraphicsDropDown = false;

function OnGUI(){
       //Make a background box
       GUI.Box(Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,200), "Darkness");

       //Make Main Menu button
       if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 - 50,250,50), "Start"))
         Application.LoadLevel(1);       

       //Make Change Graphics Quality button
       if(GUI.Button(Rect(Screen.width /2 - 100,Screen.height /2 ,250,50), "Options"))
       /* EDIT : You can toggle a boolean by affecting its opposite, with ! */
       /*{
         if(showGraphicsDropDown == false)
          showGraphicsDropDown = true;
         else
          showGraphicsDropDown = false;
       }*/
       showGraphicsDropDown = !showGraphicsDropDown;


       //Create the Graphics settings buttons, these won't show automatically, they will be called when
       //the user clicks on the "Change Graphics Quality" Button, and then dissapear when they click
       //on it again....
       if( showGraphicsDropDown ) /* EDIT boolean == true is redundant */
       {
         if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 ,250,50), "Fastest"))
          QualitySettings.currentLevel = QualityLevel.Fastest;

         if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 50,250,50), "Fast"))
          QualitySettings.currentLevel = QualityLevel.Fast;

         if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 100,250,50), "Simple"))
          QualitySettings.currentLevel = QualityLevel.Simple;

         if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 150,250,50), "Good"))
          QualitySettings.currentLevel = QualityLevel.Good;

         if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 200,250,50), "Beautiful"))
          QualitySettings.currentLevel = QualityLevel.Beautiful;

         if(GUI.Button(Rect(Screen.width /2 + 150,Screen.height /2 + 250,250,50), "Fantastic"))
          QualitySettings.currentLevel = QualityLevel.Fantastic;

         /* EDIT : Input should not be used in OnGUI */
         //if(Input.GetKeyDown("escape"))
         if( Event.current == EventType.KeyDown )
          if( Event.current.keyCode == KeyCode.Escape )
              showGraphicsDropDown = false;
       }     

       //Make quit game button
       if (GUI.Button (Rect (Screen.width /2 - 100,Screen.height /2 + 50,250,50), "Quit Game"))
         Application.Quit();
    }

[Edit by Berenger] I deleted empty lines to shorten the code and changed some stuff. Check them out, the have the mention /* EDIT ... */ before them, with the reason.

more ▼

asked Jan 06 '12 at 09:01 PM

martokio97 gravatar image

martokio97
1 5 6 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If you want to load the game from the main menu you need to create a gameobject(I recommend an empty) and have the save data stored in a script on the object, also you need to put DontDestroyOnLoad(); in the script so the object can transfer scenes safely. Then when you load the game scene the data will be in a script where you can access it.

more ▼

answered May 22 '12 at 04:07 PM

NextGenGameDesigner gravatar image

NextGenGameDesigner
36

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3729
x796
x436
x436

asked: Jan 06 '12 at 09:01 PM

Seen: 783 times

Last Updated: May 22 '12 at 04:37 PM