Unity 利用協同程序實現場景切換時加載進度的監控

 

[html] view plaincopy
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class FightTriggle : MonoBehaviour {  
  5.     private AsyncOperation async;  
  6.     int i = 0;  
  7.     void OnTriggerEnter(Collider other)  
  8.     {  
  9.         Debug.Log("打開");  
  10.         if (other.collider.gameObject.tag == "Player")  
  11.         {  
  12.             //打開副本UI  
  13.             Debug.Log("打開副本");  
  14.             StartCoroutine(GetProgress());  
  15.               
  16.         }  
  17.   
  18.     }  
  19.     IEnumerator GetProgress()  
  20.     {  
  21.         async = Application.LoadLevelAsync(0);  
  22.         yield return async;  
  23.     }  
  24.     void Update()  
  25.     {  
  26.         if (async != null)  
  27.         {  
  28.             if (!async.isDone)  
  29.             {  
  30.                 float progress = async.progress;  
  31.                 Debug.Log("加載進度  " + async.progress);  
  32.                 i++;  
  33.                 Debug.Log("" + i+async.progress);  
  34.             }  
  35.         }  
  36.          
  37.     }  
  38.     void OnTriggerExit(Collider other)  
  39.     {  
  40.         if (other.collider.gameObject.tag == "Player")  
  41.         {  
  42.             Debug.Log("關才副本");  
  43.         }  
  44.     }  
  45. }  
發佈了13 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章