遮罩的思想做进度条

2017-11-21  本文已影响10人  吃掉夏天的怪物

大圆1作为背景,就是灰色的那一部分

大圆2作为填充背景,蓝色的那一部分。为了实现填充效果,应该把其Type设置为fill,可以拖动FilledAmount观察填充再创建两个Text,一个作为进度数,一个作为说明(Loading Or Done)。

用代码实现控制

对BG附加脚本,这里用public只是方便在面板上调节

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MyprogressBar : MonoBehaviour
{
   public Transform myProgress;
   public Transform setText;
   public Transform loadingText;
   private float currentAmount = 0;
   public float moveSpeed = 15;
// Update is called once per frame
void Update () {
   if (currentAmount < 100)
  {
       currentAmount += moveSpeed*Time.deltaTime;
       setText.GetComponent<Text>().text = ((int) currentAmount).ToString() + "%";
           setText.gameObject.SetActive(true);
  }
   else
  {
       loadingText.GetComponent<Text>().text = "DONE!";
           setText.gameObject.SetActive(false);
  }
   myProgress.GetComponent<Image>().fillAmount = currentAmount/100;
}
}

emm只是总结一下方便自己看

原教程来自B站:https://www.bilibili.com/video/av12036478/?t=237

上一篇 下一篇

猜你喜欢

热点阅读