Unity中实现多个进度条积攒能量_# Unity相关技术
按下A按键发动技能,并将当前进度条积攒的能量继续在前一个进度条上继续积攒

using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
    public Slider[] progressBar;//所有的进度条

    private float totalValue;//进度条Value总和
    public float timeval;//时间间隔

    private void Update()
    {
        UpdateProgressBar();

        //释放技能
        if (Input.GetKeyDown(KeyCode.A) && totalValue >= 1)
        {
            totalValue -= 1;
        }
    }

    /// <summary>
    /// 更新进度条
    /// </summary>
    private void UpdateProgressBar()
    {
        totalValue = totalValue >= progressBar.Length ? progressBar.Length : totalValue += Time.deltaTime / timeval;

        //计算求得每个进度条的Value数值
        int len = progressBar.Length;
        for (int i = 0; i < len; i++)
        {
            progressBar[i].value = totalValue - i;
        }
    }
}