- Home /
When I "Pause" game, it return to Main Menu
I have 4 scenes: - Scene 0: Main Menu. - Scene 1 to 3: Level 1 to 3. I follow a Youtube tutorial to create a "Pause Menu" with "Resume", "Main Menu" button in each level with Escape Key, when I press the button, the Pause Menu appear and immediately the Main Menu scene is loaded. How can I fix it ? Thanks.
Here is my Pause Menu code:
using UnityEngine;
using System.Collections;
public class PauseMenu : MonoBehaviour {
public GUISkin mySkin;
private Rect windowRect;
private bool paused = false, waited = true;
void Start(){
windowRect = new Rect (Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);
}
void Update(){
if(waited)
if (Input.GetKey (KeyCode.Escape)) {
if (paused) paused = false;
else paused = true;
waited = false;
Invoke("waiting", 0.3f);
}
if (paused)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
void waiting(){
waited = true;
}
void OnGUI(){
if (paused)
windowRect = GUI.Window (0, windowRect, windowFunc, "Pause Menu");
}
void windowFunc(int id){
if (GUILayout.Button ("Resume"))
paused = false;
GUILayout.BeginHorizontal();
if (GUILayout.Button ("Option")) {
}
if (GUILayout.Button ("Quit")) {
}
GUILayout.EndHorizontal();
}
}
the error must be somewhere else because i couldnt find a problem in the script that would cause your mentioned issue. Can you post where you do a "Application.LoadLevel()" stuff.
Sorry, I find out where the error is. In my another script, I use Escape $$anonymous$$ey to return to $$anonymous$$ain $$anonymous$$enu. So I just need to change the button and no more problems. Thanks
Your answer
Follow this Question
Related Questions
Main menu not working 1 Answer
Main Menu 3d text 0 Answers
CS8025 error on play button 1 Answer
Can this be converted into C#? 2 Answers
Pause menu active when not visible 0 Answers