Scenes help organize different parts of your game or app. Managing scenes lets you switch between levels, menus, or different views easily.
Scene creation and management in Unity
using UnityEngine.SceneManagement; // Load a scene by name SceneManager.LoadScene("SceneName"); // Load a scene asynchronously SceneManager.LoadSceneAsync("SceneName"); // Get the active scene Scene activeScene = SceneManager.GetActiveScene(); // Unload a scene SceneManager.UnloadSceneAsync("SceneName");
Always add your scenes to the Build Settings in Unity to load them by name.
Use asynchronous loading to keep your game smooth during scene changes.
SceneManager.LoadScene("MainMenu");SceneManager.LoadSceneAsync("Level1");Scene current = SceneManager.GetActiveScene(); Debug.Log(current.name);
SceneManager.UnloadSceneAsync("Tutorial");This script listens for number keys 1, 2, and 3. Pressing 1 loads the "MainMenu" scene immediately. Pressing 2 loads "Level1" asynchronously. Pressing 3 prints the current scene's name in the console.
using UnityEngine; using UnityEngine.SceneManagement; public class SceneSwitcher : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { SceneManager.LoadScene("MainMenu"); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { SceneManager.LoadSceneAsync("Level1"); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { Scene active = SceneManager.GetActiveScene(); Debug.Log($"Current Scene: {active.name}"); } } }
Make sure all scenes you want to load are added in Unity's Build Settings.
Use asynchronous loading to avoid freezing the game during scene changes.
You can load multiple scenes additively to combine content from different scenes.
Scenes organize your game into separate parts like levels or menus.
Use SceneManager to load, unload, and get information about scenes.
Asynchronous loading helps keep your game smooth during scene changes.