Unity进度条加载
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class UILoadingView : MonoBehaviour
{
public Slider slider;
public Text text;
private AsyncOperation async;
void Start()
{
ChangeScene();
}
private void ChangeScene()
{
async=SceneManager.LoadSceneAsync(“MainFigthing”);
//是不是准备好,这时候肯定没有准备好,所以是false
async.allowSceneActivation = false;
}
private int myprogress;//原本进度
private int Currprogress;//当前进度
void Update()
{
//async.progress:进度 0-1
// 0-100
if (async.progress < 0.9f)
{
myprogress = Mathf.Clamp((int)(async.progress * 100), 1, 100);//进度0-90
}
else
{
myprogress = 100;//100
}
//myprogress 0-100
if(Currprogress< myprogress)
{
Currprogress++;
float rate = Currprogress / 100.0f;
slider.value = rate;
text.text = Currprogress + “%”;
}
else
{
Currprogress = 100;
async.allowSceneActivation = true;
}
}
}