首页 > 其他 > 详细

【酷熊科技】工作积累 ----------- 动画播放 直接写代码控制的

时间:2017-03-31 15:48:33      阅读:118      评论:0      收藏:0      [点我收藏+]

 

动画 播放

 

 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 }

 

【酷熊科技】工作积累 ----------- 动画播放 直接写代码控制的

原文:http://www.cnblogs.com/dudu580231/p/6651451.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!