码迷,mamicode.com
首页 > 其他好文 > 详细

战斗力数字提升的动画.

时间:2015-09-26 14:33:59      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class FrightUp_PanleMng : MonoBehaviour {
 5 
 6    // public static FrightUp_PanleMng Instance;
 7 
 8     //时间
 9     public float time_miao = 2f;
10 
11     public UILabel frightnum;//战斗力label
12 
13     public TweenAlpha tweenalpha;//显示隐藏的TWeen动画
14 
15     float start = 0;//开始数值
16     float end = 0;//结束数值
17 
18     float speed=0;//速度
19 
20     void Awake()
21     {
22       //  Instance = this;
23 
24 
25 
26       
27     }
28 
29     void Start()
30     {
31         PlayerInfo.Instance.OnPlayerInfoChanged += this.OnPlayerInfoChanged;//注册事件,
32 
33         start = PlayerInfo.Instance.Fright;//获取开始的战斗力数值
34 
35         gameObject.SetActive(false);//先隐藏
36     }
37   //事件方法
38     public void OnPlayerInfoChanged(InfoType infotype)
39     {
40         if (infotype==InfoType.FRIGHTNUM)//如果类型是战斗力
41         {
42             Show();
43         }
44     }
45 
46     public void Show()
47     {
48         end = PlayerInfo.Instance.Fright;//获取现在的战斗力
49         speed = (end - start) / time_miao;//计算出速度
50         gameObject.SetActive(true);//激活
51         tweenalpha.PlayForward();//显示动画
52         StartCoroutine(ieshow());//开始协程
53     }
54 
55     IEnumerator ieshow()
56     {
57         
58         while (start!=end)
59         {    //当end和start差距小于速度时,
60             if ((end>start&&end - start < speed)||(end<start)&&start-end<Mathf.Abs(speed))
61             {  //直接等于end
62                 start = end;
63             }
64             else
65             {  //不然就加上速度*每帧
66                 start += speed * Time.deltaTime;
67             }
68         //label赋值
69             frightnum.text = ((int)start).ToString();
70             //等待一帧
71             yield return 0;
72         }
73         tweenalpha.PlayReverse();//循环结束就播放隐藏动画
74     //等待动画播放完成
75         yield return new WaitForSeconds(0.7f);
76      //禁用
77         gameObject.SetActive(false);
78     }
79 
80 }

 

战斗力数字提升的动画.

标签:

原文地址:http://www.cnblogs.com/gzmumu/p/4840651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!