using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadSprite : MonoBehaviour
{
public Image jindu;
//异步加载场景
public AsyncOperation async;
bool isLoad;
void Start()
{
//开启协同程序
StartCoroutine(loadScene());
}
IEnumerator loadScene()
{//尝试加载场景
try
{//加载场景
async = SceneManager.LoadSceneAsync("Update_");//LoadSceneAsyne("scene2");
//加载完后不跳转
async.allowSceneActivation = false;//allowSceneAcivation = false;
}
catch (Exception er)
{//输出错误信息
Debug.Log(er);
}
while (!async.isDone && async.progress < 0.9f)
{ yield return null; }
//加载完了
isLoad = true;
}
void Update()
{
if (jindu.fillAmount < 0.9f)
{
//进度条.value = async.progress;
jindu.fillAmount += UnityEngine.Random.Range(0.0009f, 0.005f);
}
else if (isLoad == true)
{
jindu.fillAmount += UnityEngine.Random.Range(0.0009f, 0.005f);
if (jindu.fillAmount >= 1)
{//场景跳转
async.allowSceneActivation = true;
}
}
}
}