This script is attached to another scene that is not the main menu scene:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class LoadMainMenuOnclick : MonoBehaviour { private Scene scene; // Use this for initialization void Start () { scene = SceneManager.GetActiveScene(); } // Update is called once per frame void Update () { if (scene.name != "Menu") { if (Input.GetKeyDown(KeyCode.Escape)) { SceneManager.LoadSceneAsync(0); } //To check that if in gameplay mode //f in The Space Station scene or any other scene //that is not the main menu scene only then to be able //to click on escape key to load the main menu //and to check why the exit button and sound not working //when clicking pressing the escape key. // And here to also pause the game !!!!! // to check how to pause the game here when // clicking the escape key. } } } What I want is when I click the escape key to load the main menu scene that index 0 and then to pause the game. I don't want to unload or remove the current active scene when pressing escape I wan to keep both scene loaded when loading the main menu.
Not sure if to use LoadSceneAsync or just LoadScene.
When I start the game both scenes are loaded and the active scene is not the main menu but I see and use the main menu scene.
Then I click on a start game button and it's unloading the main menu scene:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class LoadScenes : MonoBehaviour { // Use this for initialization void Start () { SceneManager.LoadScene(1, LoadSceneMode.Additive); StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("The Space Station"))); } public IEnumerator WaitForSceneLoad(Scene scene) { while (!scene.isLoaded) { yield return null; } SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1)); } } When the game is running there are two loaded scenes: "Main Menu" and "The Space Station" The active scene is the "The Space Station" but the scene that load first is the main menu.
When I click the Start Game button it's unloading the Main Menu scene.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class LoadSceneOnClick : MonoBehaviour { public void ActivatePlayer() { GameControl.player.SetActive(true); SceneManager.UnloadSceneAsync(0); } } Now when I press escape I want to get back to the main menu scene to load it again and to pause the "The Space Station" scene.
I also want to save the game progress so far when pressing on escape. So it will pause the game but also will save the progress so far to a file on the hard disk.