现在的位置: 首页 > 综合 > 正文

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

2013年12月07日 ⁄ 综合 ⁄ 共 589字 ⁄ 字号 评论关闭
using UnityEngine;
using System.Collections;

public class FightTriggle : MonoBehaviour {
    private AsyncOperation async;
    int i = 0;
    void OnTriggerEnter(Collider other)
    {
        Debug.Log("打开");
        if (other.collider.gameObject.tag == "Player")
        {
            //打开副本UI
            Debug.Log("打开副本");
            StartCoroutine(GetProgress());
            
        }

    }
    IEnumerator GetProgress()
    {
        async = Application.LoadLevelAsync(0);
        yield return async;
    }
    void Update()
    {
        if (async != null)
        {
            if (!async.isDone)
            {
                float progress = async.progress;
                Debug.Log("加载进度  " + async.progress);
                i++;
                Debug.Log("" + i+async.progress);
            }
        }
       
    }
    void OnTriggerExit(Collider other)
    {
        if (other.collider.gameObject.tag == "Player")
        {
            Debug.Log("关才副本");
        }
    }
}

抱歉!评论已关闭.