Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5.  
  6. public class LevelLoader : MonoBehaviour
  7. {
  8.     public GameObject loadingScreen;
  9.     public Slider Slider;
  10.     public Text ProgressText;
  11.  
  12.  
  13.     private void Awake()
  14.     {
  15.         DontDestroyOnLoad(this);
  16.     }
  17.  
  18.     public void LoadLivel(int sceneIndex)
  19.  
  20.     {
  21.         StartCoroutine(LoadAsynchronously(sceneIndex));
  22.     }
  23.  
  24.     IEnumerator LoadAsynchronously(int sceneIndex)
  25.     {
  26.         var operation = SceneManager.LoadSceneAsync(sceneIndex);
  27.         loadingScreen.SetActive(true);
  28.  
  29.         while (!operation.isDone)
  30.         {
  31.             float progress =(operation.progress/0.9f);
  32.             Debug.Log("progress " + progress);
  33.             Slider.value = progress;
  34.             ProgressText.text = progress * 100 + "%";
  35.             yield return null;
  36.         }
  37.  
  38.         loadingScreen.SetActive(false);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement