标签:
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