Hey, I've created a game now and main menu but I also want an ingame menu...
Ex. I click on Esc and the game pause and 3 different text's shows up:
Resume
What to do
Quit ( Back to Main Menu )
When I click on ( Quit ) a specific level ( Main Menu ) will load , when I click on ''Resume'' the game will start again and when I click on ''What to do'' a text will pop up.
ok! i happily copy some parts of my code for you here. paused variable will be toggled by escape key in my code. then in GUI depending on it's value (if it's true) i draw the menu
if (paused)
{
GUI.skin = skin;
GUI.Box(pauseRect, "");
GUILayout.BeginArea(pauseRect);
GUILayout.BeginVertical();
AudioListener.volume = GUILayout.HorizontalSlider(AudioListener.volume, 0, 1);
GUILayout.Label(volStr);
if (GUILayout.Button(resumeStr))
{
UnPause();
}
if (GUILayout.Button(returnToMainMenuStr))
{
UnPause();
Application.LoadLevel(Application.loadedLevel-1); //main menu is the level before this one in my game, you can use a level name instead
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
the code also has a part for changing volume. the defenition of Pause and UnPause methods is
/// <summary>
/// pauses the game
/// </summary>
public static void Pause()
{
levelManager.paused = true;
Time.timeScale = 0;
}
/// <summary>
/// resumes the game
/// </summary>
public static void UnPause()
{
levelManager.paused = false;
Time.timeScale = 1;
}
pausing mechanics in your game is dependent to your implementation. in my game i set timeScale to 0 to stop all time dependent things and in other places i check the value of paused to see if the game is paused or not and should i execute my code or not? the game is a tetris like one so there are not many scripts and this approach works. you might want to use another approach.
for checking escape key simply use Input.GetKeyDown() in an Update function.
put /// (three forward slashes) on top of your methods and then fill the inline documentation, it's a good practice
You generally do not want to use escape for triggering the pause menu, because it also makes you exit fullscreen mode and unhides the mouse, if you're using the webplayer.
That's just one of two lines that put a layer over the camera. Go to the lines the compiler point out and edit them out.
– anon73820239Just remove it. You can't use filters in indy.
– anon73820239Of course it is. When unpausing just hide them again...
– anon73820239