Good day to all. Faced such a problem, when I go to the stage with the game, the scene of the main me remains open. Script go to the scene:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class LoadLevel : MonoBehaviour { public Button LoadButton; void Start() { Button btn = LoadButton.GetComponent<Button>(); btn.onClick.AddListener(TaskOnClick); } void TaskOnClick() { Debug.Log("Loading"); Debug.Log("QuitingScene"); Application.Quit(); //здесь пытаюсь закрыть сцену LoadGame(); Debug.Log("Load!!"); } void LoadGame() { SceneManager.LoadScene("main", LoadSceneMode.Additive); } } 

Actually the question:

You can help, suggest or push on how to close the previous scene ..

Thank you in advance!

    1 answer 1

    Application.Quit(); - This gives a signal to exit the application completely, but click on the cross in the upper right corner of the window. But the previous scene is usually automatically "killed" when loading a new one. So first of all you need to remove Application.Quit();

    And it should be mentioned that when using mode in the LoadScene method LoadScene you would then have to write this:

     SceneManager.LoadScene("main", LoadSceneMode.Single); 

    because according to the documentation

    • Additive - adds a scene to the list of loaded
    • Single - closes all scenes and loads this one.

    But as I understand it, you can do without it, i.e. write while just SceneManager.LoadScene("main");

    • Thank you, I'll check it tomorrow) - ThusMad