unity中实现场景之间加载进度条

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI; public class LoadingScene : MonoBehaviour
{
public Image progressImg;
private AsyncOperation async;
public Text text; private int curProgressVaule = ;//计数器
// Use this for initialization
void Start ()
{
StartCoroutine(LoadScene());
} IEnumerator LoadScene()
{
async = SceneManager.LoadSceneAsync("game");//异步跳转到game场景
async.allowSceneActivation = false;//当game场景加载到90%时,不让它直接跳转到game场景。
yield return async;
}
// Update is called once per frame
void Update () { if (async == null)
{
return;
} int progressVaule = ; if (async.progress < 0.9f)
{
progressVaule = (int) async.progress*;
}
else
{
progressVaule = ;
} if (curProgressVaule < progressVaule)
{
curProgressVaule++;
}
text.text = curProgressVaule + "%";
progressImg.fillAmount = curProgressVaule/100f;
if (curProgressVaule == )
{
async.allowSceneActivation = true;
}
}
}
上一篇:接口自动化测试链接https://www.cnblogs.com/finer/


下一篇:Unity 异步加载进度条