一、进度条-线状
Step1:创建Slider和Text,随便摆一下
Step2:写脚本
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LineLoad : MonoBehaviour
{
//进度显示
public Text text;
//进度条
public Slider progressSlider;
private void Start()
{
StartCoroutine(LoadScene());
}
IEnumerator LoadScene()
{
AsyncOperation operation = SceneManager.LoadSceneAsync("ExcelScene");
while (!operation.isDone)
{
progressSlider.value = operation.progress;
text.text = operation.progress * 100 + "%";
if (operation.progress >= 0.9f)//如果进度条已经到达90%
{
progressSlider.value = 1; //那就让进度条的值编变成1
text.text = "加载完成!";
}
yield return null;
}
}
}
Step3:把场景加载到BuildSetting中
Done!
文章来源:https://uudwc.com/A/8pY2n
二、进度条-饼状
Step1:找到类似圆环的图片,做成Image,再加一个Text
Step2:把Image的类型改成Filled类型,起始点Origin改成Top,Clockwise改为false
fillAmount改为0
Step3:写脚本
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class CircleLoad : MonoBehaviour
{
public Image m_Image;
public Text m_Text;
private void Start()
{
m_Image.fillAmount = 0;
StartCoroutine(LoadSceneCircle());
}
IEnumerator LoadSceneCircle()
{
AsyncOperation operation = SceneManager.LoadSceneAsync("ExcelScene");
while (!operation.isDone)
{
m_Image.fillAmount = operation.progress / 100f ;
m_Text.text = operation.progress * 100 + "%";
if (operation.progress >= 0.9f)//如果进度条已经到达90%
{
m_Image.fillAmount = 1; //那就让进度条的值编变成1
m_Text.text = "加载完成!";
}
yield return null;
}
}
}
这里和上面不一样的地方是,这里主要用到了fillAmout属性,而进度条就只需要Slider的Process属性即可
怎么样,是不很简单?文章来源地址https://uudwc.com/A/8pY2n