using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadP : MonoBehaviour {
//float timer = 0f;
UISlider slider;//进度条
int nowProgress, toProgress;//当前进度、异步加载进度
AsyncOperation ao;//异步加载对象
void Start () {
slider = transform .GetChild(1).GetChild (0).GetComponent <UISlider >();//获取UI界面进度条
StartCoroutine(LoadScene ());//开启异步加载协程
}
void Update () {
//timer += Time.deltaTime;
//slider.value = timer / 10;
// async.progress 表示正在读取的场景的进度值 0---0.9
// 如果当前的进度小于0.9,说明它还没有加载完成,就说明进度条还需要移动
// 如果,场景的数据加载完毕,async.progress 的值就会等于0.9
if (ao.progress <0.9f)
{
toProgress = (int)(ao.progress *100);
}
else
{
toProgress = 100;
}
if (nowProgress <toProgress )
{
nowProgress++;//当前进度累加 注:在UI界面只能看到当前进度
}
slider.val
Unity:游戏场景异步加载
最新推荐文章于 2024-07-04 23:22:27 发布