Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class LevelLoader : MonoBehaviour
- {
- public GameObject loadingScreen;
- public Slider Slider;
- public Text ProgressText;
- private void Awake()
- {
- DontDestroyOnLoad(this);
- }
- public void LoadLivel(int sceneIndex)
- {
- StartCoroutine(LoadAsynchronously(sceneIndex));
- }
- IEnumerator LoadAsynchronously(int sceneIndex)
- {
- var operation = SceneManager.LoadSceneAsync(sceneIndex);
- loadingScreen.SetActive(true);
- while (!operation.isDone)
- {
- float progress =(operation.progress/0.9f);
- Debug.Log("progress " + progress);
- Slider.value = progress;
- ProgressText.text = progress * 100 + "%";
- yield return null;
- }
- loadingScreen.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement