using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Loading : MonoBehaviour
{
public Image progessImg;//滑动的图片
public Text progessTxt;//显示加载的文本
private float currentValue = 0;//当前的值
private float addValue;//每次增加的值
private AsyncOperation async;
private void Start()
{
StartCoroutine(LoadScene());
}
private void Update()
{
if (async==null)
{
return;
}
float progessValue = 100;
if (currentValue<progessValue)
{
addValue += 20 * Time.deltaTime;
currentValue = (int)addValue;
}
progessTxt.text = currentValue + "%";
progessImg.fillAmount = currentValue / 100f;
if (currentValue==100)
{
async.allowSceneActivation = true;
progessTxt.text = "加载完成!";
}
}
IEnumerator LoadScene()
{
yield return new WaitForSeconds(1.5f);
async = SceneManager.LoadSceneAsync(2);
async.allowSceneActivation = false;
yield return async;
}
}
Unity中的异步加载场景
最新推荐文章于 2023-11-25 11:46:38 发布