Unity 利用协同程序实现场景切换时加载进度的监控

 

[html]   view plain copy
  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. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值