private IEnumerator ELoadScene(SceneName scene) { isLoading = true; // Reset all tweens to avoid updates on destroyed objects LeanTween.reset(); // Load scene asynchronously loadingOperation = SceneManager.LoadSceneAsync((int)scene); loadingText.text = "Loading..."; loadingIcon.StartLoading(); float loadProgress = 0; float elapsedTime = 0; bool first = true; if (levelScene.Contains(scene)) { loadingOperation.allowSceneActivation = false; } SoundController.Instance.DimMusic(true, minLoadingTime, 10); while (!loadingOperation.isDone) { loadProgress = Mathf.Min(elapsedTime / minLoadingTime, loadingOperation.progress); loadingBar.fillAmount = loadProgress + 0.1f; if (loadProgress >= 0.9f && !loadingOperation.allowSceneActivation) { if (first) { first = false; SoundController.Instance.PlaySound(SoundName.UIButton1); loadingIcon.StopLoading(); loadingText.text = "Press Enter to start"; LeanTween.scale(loadingText.rectTransform, 1.05f * Vector3.one, 0.5f).setLoopPingPong().setEaseOutCubic(); } if (Input.GetKeyDown(KeyCode.Return)) { loadingOperation.allowSceneActivation = true; } } elapsedTime += Time.deltaTime; yield return(null); } LeanTween.cancel(loadingText.rectTransform); LeanTween.scale(loadingText.rectTransform, Vector3.one, 0); if (levelScene.Contains(scene)) { if (storedItems.Count > 0) { GameManager.instance.GetPlayer().items.SetItem(storedItems[0], 0); GameManager.instance.GetPlayer().items.SetItem(storedItems[1], 1); } } loadingIcon.StopLoading(); StartCoroutine(EShowLoadingScreen(false)); isLoading = false; }