一、进度条-线状
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!
二、进度条-饼状
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://www.toymoban.com/news/detail-605124.html
怎么样,是不很简单?文章来源地址https://www.toymoban.com/news/detail-605124.html
到了这里,关于Unity——两种进度条的制作的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!