Load sequence frame pictures dynamically,
set the playback frame rate according to the situation, and
dynamically control playback.
using UnityEngine;
using System.Collections;
public class TextureResource : MonoBehaviour {
private Sprite[] animTime; //序列帧资源
private float FPS = 25; //播放序列帧的刷新率
[HideInInspector]
public float time; //计时器,满1/fps则切换下一张序列帧图
[HideInInspector]
public int nowFram; //当前帧数
public Sprite animTime0; //当前的序列帧图
void Start ()
{
StartCoroutine(animTimeResource());
Debug.Log("加载倒计时的图片");
}
IEnumerator animTimeResource()
{
animTime = Resources.LoadAll<Sprite>("CountDown");
yield return (animTime);
}
// Update is called once per frame
void Update ()
{
if (nowFram < animTime.Length) {
time += Time.deltaTime;
if (time >= 1 / FPS)
{
nowFram++;
time = 0;
if (nowFram >= animTime.Length - 1)
{
nowFram = animTime.Length - 1;
}
transform.GetComponent<SpriteRenderer>().sprite = animTime[nowFram];
}
}
if (nowFram == animTime.Length - 1) {
Debug.Log("倒计时序列帧结束");
Application.LoadLevel("beidouScene 1");
}
}
}