I have a menu Scene and a level Scene. I want to Load the level Scene from the Menu with a button. The first time it’s working perfect. Like the Panel fading out when I click the Level Button and then a AsyncOperation.progress shows up on Text, when it’s done it’s loading the Level. However when I press Escape and go back to MainMenu and try it again nothing happens.
This is my LevelManager Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelMenuManager : MonoBehaviour
{
public GameObject _FadeScenePanel;
public GameObject _FadingStarterObj;
public Text _loadingProgressText;
private AsyncOperation _asyncOperation;
private void Awake()
{
/*
DontDestroyOnLoad(this.gameObject);
if (GameObject.FindGameObjectsWithTag("LevelMenuManager").Length > 1)
Destroy(GameObject.FindGameObjectWithTag("LevelMenuManager"));
*/
}
public void TheBeginning()
{
StartCoroutine(LoadScene(1));
}
private IEnumerator LoadScene(int _buildIndex)
{
_FadingStarterObj.SetActive(true);
_FadingStarterObj.GetComponent<FadeScenePanel>().enabled = true;
yield return new WaitForSeconds(3f);
//Loads Scene
_asyncOperation = SceneManager.LoadSceneAsync(_buildIndex, LoadSceneMode.Single);
//Doesn't allow Scene to activate yet
_asyncOperation.allowSceneActivation = false;
//While loading and still not done //DO STUFF
while (!_asyncOperation.isDone)
{
//Set progress to display /normaly progress 0 - 1, multiplied by 100 its 100%
_loadingProgressText.gameObject.SetActive(true);
_loadingProgressText.text = Mathf.RoundToInt(_asyncOperation.progress * 100f) + "%";
if (_asyncOperation.progress >= 0.89f)
{
_asyncOperation.allowSceneActivation = true;
}
yield return null;
}
}