Unity学习之创建圆形进度条

这是在youtube上学的,我简化了一下。youtube视频教学地址:https://www.youtube.com/watch?v=f6dEj7-G-Fw

 

1.在Hierarchy面板中右键UI-Canvas,再选中Canvas,右键UI-Images。并且把这个Images重命名为circleProcessBar.

再选中circleProcessBar,右键UI-Images。并且把这个Images重命名为process.

再选中circleProcessBar,右键UI-Images。并且把这个Images重命名为top.

 

2.

再把process的inspector面板中设置如图1。其中color设置项alpha值(透明度)设置为0.

把top设置成图2

现在就是编写代码的时候了

 在assets面板中右键Creat-C# script。并命名好为mm。(可随意取)

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine.UI;
 4 using UnityEngine;
 5 
 6 public class mm : MonoBehaviour {
 7     [SerializeField] public float speed;
 8     public Transform LoadingBar;
 9     [SerializeField] private float currentAmount;
10     // Use this for initialization
11     void Start () {
12         currentAmount = 0;
13     }
14     
15     // Update is called once per frame
16     void Update () {
17         if (currentAmount < 100)
18         {
19             currentAmount += speed*Time.deltaTime;
20         }
21         LoadingBar.GetComponent<Image>().fillAmount = currentAmount / 100;
22     }
23 }

把代码打好之后,把它拖入circleProcessBar中。

把process拖入Loading Bar中,并且Speed设置为30.即可

这样就做好了。。

一播放,就能看到进度条走动啦。。

 

posted @ 2017-03-10 13:29  Centful  阅读(2878)  评论(0编辑  收藏  举报