当前位置:   article > 正文

Unity——两种进度条的制作_unity进度条

unity进度条

一、进度条-线状

Step1:创建Slider和Text,随便摆一下

 Step2:写脚本

  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5. public class LineLoad : MonoBehaviour
  6. {
  7. //进度显示
  8. public Text text;
  9. //进度条
  10. public Slider progressSlider;
  11. private void Start()
  12. {
  13. StartCoroutine(LoadScene());
  14. }
  15. IEnumerator LoadScene()
  16. {
  17. AsyncOperation operation = SceneManager.LoadSceneAsync("ExcelScene");
  18. while (!operation.isDone)
  19. {
  20. progressSlider.value = operation.progress;
  21. text.text = operation.progress * 100 + "%";
  22. if (operation.progress >= 0.9f)//如果进度条已经到达90%
  23. {
  24. progressSlider.value = 1; //那就让进度条的值编变成1
  25. text.text = "加载完成!";
  26. }
  27. yield return null;
  28. }
  29. }
  30. }

Step3:把场景加载到BuildSetting中

Done!

二、进度条-饼状

Step1:找到类似圆环的图片,做成Image,再加一个Text

 Step2:把Image的类型改成Filled类型,起始点Origin改成Top,Clockwise改为false

              fillAmount改为0

 Step3:写脚本

  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5. public class CircleLoad : MonoBehaviour
  6. {
  7. public Image m_Image;
  8. public Text m_Text;
  9. private void Start()
  10. {
  11. m_Image.fillAmount = 0;
  12. StartCoroutine(LoadSceneCircle());
  13. }
  14. IEnumerator LoadSceneCircle()
  15. {
  16. AsyncOperation operation = SceneManager.LoadSceneAsync("ExcelScene");
  17. while (!operation.isDone)
  18. {
  19. m_Image.fillAmount = operation.progress / 100f ;
  20. m_Text.text = operation.progress * 100 + "%";
  21. if (operation.progress >= 0.9f)//如果进度条已经到达90%
  22. {
  23. m_Image.fillAmount = 1; //那就让进度条的值编变成1
  24. m_Text.text = "加载完成!";
  25. }
  26. yield return null;
  27. }
  28. }
  29. }

这里和上面不一样的地方是,这里主要用到了fillAmout属性,而进度条就只需要Slider的Process属性即可

怎么样,是不很简单?

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/91997
推荐阅读
相关标签
  

闽ICP备14008679号