欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UGUI Image显示倒计时

程序员文章站 2022-05-30 17:38:11
...

UGUI Image显示倒计时

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

public class UIResume : MonoBehaviour
{
    public Image imgCount;  //Image
    public Sprite[] spCount;//Sprite
   
    public void StartCount()
    {
        Show();
        StartCoroutine(StartCountCor());//开始倒计时
    }

    IEnumerator StartCountCor()
    {
        int i = 3;
        while (i > 0)
        {
            imgCount.sprite = spCount[i - 1];
            i--;
            yield return new WaitForSeconds(1);//等待1秒
            if (i <= 0)
            {
                break;
            }
        }       
    }

   
}

 

相关标签: UGUI