- Home /
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.
Answer by NextGenGameDesigner · May 22, 2012 at 04:07 PM
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.
Your answer
Follow this Question
Related Questions
Load last checkpoint from main menu 2 Answers
How to store a boolean for each variable in a class 1 Answer
Save/Load/New 1 Answer
Save/Load Game and buttons New Game/Load Game? 1 Answer
Problem Saving game progress 1 Answer