using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
public class SceneLoader : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI loadingText = null;
private static string sceneToLoadFromOrk = null;
private bool loading = false;
#region ORK static methods
public static void LoadScene(string sceneName, LoadSceneMode mode)
{
HandleLoadScene(sceneName);
}
public static void LoadSceneAsync(string sceneName, LoadSceneMode mode)
{
HandleLoadScene(sceneName);
}
private static void HandleLoadScene(string sceneName)
{
sceneToLoadFromOrk = sceneName;
SceneManager.LoadScene("LoadingScreen", LoadSceneMode.Single);
}
#endregion
private void Start()
{
StartCoroutine(LoadORKScene());
}
IEnumerator LoadORKScene()
{
loading = true;
var ao = SceneManager.LoadSceneAsync(sceneToLoadFromOrk);
ao.allowSceneActivation = false; // Wait until loading reaches 100%
// Wait for the scene to load
while (!ao.isDone)
{
// When loading is complete, activate the scene
if (ao.progress >= 0.9f)
{
ao.allowSceneActivation = true;
}
yield return null;
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
The variables being stuck, I'd guess that they're set after the variables are already loaded - e.g. in case they come from some still running schematic or other code (like a 3rd party day-night-cycle asset), that might still set it while loading.
Handling your persistent objects depends on how they're used, e.g. if they need to do stuff when starting or stopping the game, you can register to event handlers in Maki.Game to get notified of starting or stopping the game (e.g. Maki.Game.StopGameCalled).
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!