Game Development Reference
In-Depth Information
9.
Add the new menu to the Build Settings, and move it into the level 1 position,
putting the GardenLevel1 into the number 2 slot.
10.
Click Build, and overwrite.
11.
Close the Build Settings.
To view the Main Menu, once the player has left the StartMenu, you will have to give the player a way
to access it from in the game. Depending on the platform, that could be via keyboard, mouse pick,
or screen touch. In this game, the cursor is suppressed while the player is controlling the Gnomatic
Garden Defender in the garden, so the most logical option is a keyboard key. The code is not object
specific, so it should be put on the object that will exist in only the garden level(s).
1.
Open the GardenLevel1 scene.
The Game Manager object has a GameMisc script that should be the perfect place for your code.
The F1 key is quite often used to bring up help menus, so that would be a good choice. A search for
“keycodes” in the Scripting Reference will give you a complete list to choose from.
2.
Open the GameMisc script.
In the Update function, add
3.
if (Input.GetKeyDown(KeyCode.F1)) {
Screen.showCursor = true; // show the cursor
Application.LoadLevel(1); // load the Main Menu
}
4.
Save the script, and test by pressing the F1 key while in the garden level.
The menu comes up, but there isn't much you can do until the other menus are finished.
5.
Save the scene.
The Settings Menu
The options offered to the player are minimal for this little game. The “difficulty” will be adjustable
and the audio volume for the ambient sounds will also be adjustable. Both will use Horizontal Sliders
from the Unity GUI. You can repurpose a lot of the MainMenu to speed things up.
1.
Open the blocked-in SettingsMenu scene.
2.
Focus in on the Main Camera.
3.
Add a new Empty GameObject, and name it Settings Menu.
4.
From the Menu Scripts folder, duplicate the MainMenuGUI script and name it
SettingsGUI .
5.
Open the script, and change the class declaration to match the new name:
public class SettingsGUI : MonoBehaviour {
 
Search WWH ::




Custom Search