using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; public sealed class SceneLoader : MonoBehaviour { [SerializeField] private string destination = "LabDestination"; private bool loading; private void Awake() { DontDestroyOnLoad(gameObject); } [ContextMenu("Load Destination")] public void LoadDestination() { if (!Application.isPlaying || loading) return; if (!Application.CanStreamedLevelBeLoaded(destination)) { Debug.LogError("Destination is not available: " + destination, this); return; } StartCoroutine(Load()); } private IEnumerator Load() { loading = true; AsyncOperation operation = SceneManager.LoadSceneAsync(destination, LoadSceneMode.Single); if (operation == null) { loading = false; yield break; } yield return operation; Debug.Log("Loaded: " + SceneManager.GetActiveScene().name, this); loading = false; } }