using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; public class LoadManager : MonoBehaviour { private AsyncOperation asyncLoad; [Header("Scene Name (must match Build Settings)")] [SerializeField] private string sceneName; void Start() { PreloadNextScene(sceneName); } public void PreloadNextScene(string sceneName) { StartCoroutine(LoadSceneAsync(sceneName)); } IEnumerator LoadSceneAsync(string sceneName) { asyncLoad = SceneManager.LoadSceneAsync(sceneName); asyncLoad.allowSceneActivation = false; while (!asyncLoad.isDone) { Debug.Log("Loading: " + (asyncLoad.progress * 100f) + "%"); if (asyncLoad.progress >= 0.9f) { Debug.Log("Scene ready to activate"); yield break; } yield return null; } } public void ActivateScene() { if (asyncLoad != null) { asyncLoad.allowSceneActivation = true; } } }