动画 播放
1 using UnityEngine; 2 using System.Collections; 3 4 public class GameLoading : MonoBehaviour { 5 6 public bool isAnimate = true; // hero 是否播放动画 用于暂停游戏等 7 public float animateFrameCountPerSecond = 0.1f; // hero 每秒播放 图片 多少张 8 public float timeAnimatePlay = 0.0f; // hero 动画已经播放的时长 9 public Sprite[] animatorFrames; // hero 动画 播放的 图片 数组 10 11 12 // Use this for initialization 13 void Start () { 14 15 } 16 17 // Update is called once per frame 18 void Update () 19 { 20 LoadingAnimate(); 21 } 22 23 private void LoadingAnimate() 24 { 25 if (!isAnimate) 26 return; 27 28 timeAnimatePlay += Time.deltaTime; 29 int indexAnimate = (int) (timeAnimatePlay / (1.0f/(animateFrameCountPerSecond*animatorFrames.Length))); 30 31 indexAnimate %= animatorFrames.Length; 32 gameObject.GetComponent<SpriteRenderer>().sprite = animatorFrames[indexAnimate]; 33 34 } 35 36 }