Unity使用协程技术制作倒计时器
生活随笔
收集整理的這篇文章主要介紹了
Unity使用协程技术制作倒计时器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先上效果圖
圖片資源來自http://www.51miz.com/
1.素材準備
在http://www.51miz.com/搜索png格式的數字圖片,用Unity自帶的圖集制作工具,進行分割。Container是一個Image,很簡單就不細說了。
2.素材準備好,就制作UI了。
3.前戲做好就可以擼代碼了。
using System.Collections; using UnityEngine; using UnityEngine.UI; namespace View {public class MyTimer : MonoBehaviour{public float timeDelay = 1f; //時間間隔public Sprite[] numbersImage; //替換的圖片public Image numbersContainer; //顯示圖片的容器// private bool _onOff = true; //開關// private short curImageIndex = 0; //當前播放的圖片編號private void Start(){StartCoroutine("StartTimer");}/// <summary>/// 使用協程等待,替換圖片/// </summary>/// <returns></returns>private IEnumerator StartTimer(){int index = 0; //當前播放的圖片編號while (index < (numbersImage.Length)){numbersContainer.sprite = numbersImage[index]; //替換圖片yield return new WaitForSeconds(timeDelay);++index;}}}}?
轉載于:https://www.cnblogs.com/blackteeth/p/10182975.html
總結
以上是生活随笔為你收集整理的Unity使用协程技术制作倒计时器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CI框架--加载静态内容
- 下一篇: FlashCC学习札记