1 资源test.jpg(如下)放入Resources文件夹
2 切割图片
点击图片,在inspector中,选择Texture Type为Sprite(2D and UI),然后点击Sprite Editor,在弹出界面中点击Slice自动切割图片
3 Hierarchy中新建一个Sprite,然后添加个脚本,脚本中代码如下
登录后复制
using UnityEngine;
using System.Collections;
public class TSpriteAnimator : MonoBehaviour {
//
float framePerSecond = 60f;
SpriteRenderer sr;
Sprite[] sp;
void Start () {
sr = renderer as SpriteRenderer;
sp = Resources.LoadAll<Sprite>("test");
}
void Update () {
float f = Time.timeSinceLevelLoad;
int index = (int)(f*framePerSecond);
index = index % sp.Length;
sr.sprite = sp[index];
}
}
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删