[Unity][UGUI][协程]圆环进度条读条协程延迟倒计时
发布日期:2021-05-09 11:54:47 浏览次数:2 分类:技术文章

本文共 1765 字,大约阅读时间需要 5 分钟。

实现的功能是,当 按下按钮后,就会对 显示 出 倒计时 的圆环进度条 读条的 UI。通过 协程 函数 ,延迟 实现函数功能。

圆环进度条 的 动画 ,相关文章1

脚本 相关资料2

using System.Collections;using UnityEngine;using UnityEngine.UI;public class WaitProgressBar : MonoBehaviour {    public Text TimeLabel;//时间显示UI    public Slider slider;//进度条 滑条 UI    public GameObject progressBar;//圆环 进度条UI    public float sumTime;//总时间 单位 秒    private float currentTime;//当前 的时间 秒    public float countdownTime = 1;//倒计时 时间间隔    private void Awake()    {        currentTime = sumTime;    }    private void Start()    {        //StartCoroutine("startCountDown");        //currentTime = sumTime; 如果在 Start函数内,设置 currentTime,会使得 这个currentTime的值 无效。    }    public void progressBarStartCountDown(float time)    {        StartCoroutine(startCountDown(time));    }    private IEnumerator startCountDown(float _time)    {        sumTime = _time;        currentTime = sumTime;        progressBar.SetActive(true);//圆环 进度条UI 为真        while (currentTime >= 0)        {            currentTime = currentTime - countdownTime;//总时间 单位 秒,倒计时            TimeLabel.text = "Time:" + currentTime;//时间显示UI            slider.value = 1 - (currentTime / sumTime);            if (currentTime == 0)            {                currentTime = 0;                Debug.Log("gameOver");                TimeLabel.text = "Time:" + currentTime;                progressBar.SetActive(false);//圆环 进度条UI 为假                yield break;//停止 协程            }            else if (currentTime > 0)            {                yield return new WaitForSeconds(countdownTime);// 每次 自减1,等待 1 秒            }        }    }}

//延迟等待 函数    IEnumerator Wait()    {        // suspend execution for 5 seconds          yield return new WaitForSeconds(5);        //... 一些函数    }
延迟 等待倒计时的函数 如上代码所示。

相关文章:

1. 

2. 

3.

转载地址:https://blog.csdn.net/BuladeMian/article/details/79206814 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:[Unity]建造放置系统BuildSystem
下一篇:[Unity][UGUI][Animation]圆环进度条读条特效设置制作

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2023年08月29日 09时09分43秒