标签:
1 using UnityEngine; 2 using System.Collections; 3 4 public class hero : MonoBehaviour 5 { 6 private bool animation = true; //动画开关 7 8 public int frameCountPerSecond = 10; //每秒播放10帧 9 private float time = 0; //计时器 10 11 public Sprite[] sprite; //存放sprite的数组 12 13 // Update is called once per frame 14 void Update () { 15 if (animation) //如果开关打开的时候 16 { 17 time += Time.deltaTime; //计时器开始计时 18 int frameIndex = (int)(time / (1f / frameCountPerSecond)); //声明一个指定帧(1,2,3,4......) 19 int frame = frameIndex % 2; //当前只有两个动画所以和2求余,得出0,1,0,1...... 20 this.GetComponent<SpriteRenderer>().sprite = sprite[frame]; //得到游戏组件并让它的sprite等于sprite[frame] 21 } 22 } 23 }
标签:
原文地址:http://www.cnblogs.com/fuperfun/p/5341322.html