public Slider slider;//进度条
public Text text;//百分制显示进度加载情况
public void StartGame(int index)
{
StartCoroutine(loginMy(index));
}
/// <summary>
/// 切换场景加载
/// </summary>
/// <param name="index">场景代码</param>
/// <returns></returns>
IEnumerator loginMy(int index)
{
int displayProgress = 0;
int toProgress = 0;
AsyncOperation op = SceneManager.LoadSceneAsync(index); //此处改成要加载的场景名
op.allowSceneActivation = false;
while (op.progress < 0.9f) //此处如果是 <= 0.9f 则会出现死循环所以必须小0.9
{
toProgress = (int)op.progress * 100;
while (displayProgress < toProgress)
{
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
}
toProgress = 100;
while (displayProgress < toProgress)
{
++displayProgress;
SetLoadingPercentage(displayProgress);
yield return new WaitForEndOfFrame();
}
op.allowSceneActivation = true;
}
/// <summary>
/// 显示进度
/// </summary>
/// <param name="displayProgress">进度值</param>
private void SetLoadingPercentage(int displayProgress)
{
slider.value = displayProgress;
text.text = displayProgress.ToString() + "%";
}
进度条就是ui里面的slider组件,然后自己加个text进行显示百分比,背景什么的可以用image做,
自己添加一个button按钮组件进行委托或者拖拽的方式加入单击事件进行运行。