Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using System.Linq;
- public class LevelManager : MonoBehaviour
- {
- public static LevelManager Instance;
- public Slider progressBar;
- public GameObject transitionsContainer;
- private SceneTransition[] transitions;
- private void Awake()
- {
- if (Instance == null)
- {
- Instance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- }
- private void Start()
- {
- transitions = transitionsContainer.GetComponentsInChildren<SceneTransition>();
- }
- public void LoadScene(string sceneName, string transitionName)
- {
- StartCoroutine(LoadSceneAsync(sceneName, transitionName));
- }
- private IEnumerator LoadSceneAsync(string sceneName, string transitionName)
- {
- SceneTransition transition = transitions.First(t => t.name == transitionName);
- AsyncOperation scene = SceneManager.LoadSceneAsync(sceneName);
- scene.allowSceneActivation = false;
- yield return transition.AnimateTransitionIn();
- progressBar.gameObject.SetActive(true);
- do
- {
- progressBar.value = scene.progress;
- yield return null;
- } while (scene.progress < 0.9f);
- yield return new WaitForSeconds(1f);
- scene.allowSceneActivation = true;
- progressBar.gameObject.SetActive(false);
- yield return transition.AnimateTransitionOut();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment