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]; } }