Hyluss

[Unity] Load Scene async

Oct 8th, 2017
335
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. AsyncOperation async;
  2. IEnumerator LoadNewScene(string stringZaladuj)
  3. {
  4.     yield return new WaitForSeconds (3);
  5.     async = Application.LoadLevelAsync(stringZaladuj);
  6.     async.allowSceneActivation = false;
  7.  
  8.     while (async.progress < 0.9f)
  9.     {
  10.         yield return null;
  11.     }
  12.     Debug.Log ("the Game has been loaded");
  13.  
  14.     while(!Input.GetMouseButtonDown(0))
  15.     {          
  16.         yield return null;
  17.     }
  18.        
  19.     async.allowSceneActivation = true;
  20. }
  21.  
  22.  
  23.  IEnumerator LoadNewScene(string sceneName)
  24.     {
  25.         AsyncOperation async;
  26.         async = SceneManager.LoadSceneAsync(sceneName);
  27.  
  28.         while(!async.isDone)
  29.         {
  30.             Debug.Log(async.progress);
  31.             float progress = Mathf.Clamp01(async.progress / .9f);
  32.  
  33.             loadingText.text =  string.Format("Loading {0}%",async.progress * 100); //"Loading "+ (progress * 100) + "%";//
  34.             yield return null;
  35.         }
  36.     }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment