序列帧动画作为一种2D游戏中经常采用的动画技术,使用unity也是很好实现的。只要在场景中新建一个Quad,然后在添加上如下脚本即可:
using UnityEngine;
using System.Collections;
public class AnimateTest : MonoBehaviour {
private int startIndex = 266;
private int lastIndex = 331;
private string path = "dance/dance_";
private int currentIndex;
Texture frameAniTex;
public float framesPerSecond;
// Use this for initialization
void Start ()
{
currentIndex = startIndex;
}
void Update()
{
AnimaAlways();
}
// Update is called once per frame
void AnimaAlways()
{
int nowIndex = (int)(Time.time * framesPerSecond) % (lastIndex - startIndex+1);
if (currentIndex != startIndex + nowIndex)
{
currentIndex = startIndex + nowIndex;
frameAniTex = (Texture)Resources.Load(path + currentIndex.ToString(&#