Currently using Ngui for interface development, please add the Ngui plugin before testing.
using unityengine;using system.collections;public class numberanimation : monobehaviour{ public uilabel valuetext; float mNumUpdateTime = 0; float mAnimTotalTime = 1.5f; int mstartvalue = 0; int mfinalvalue = 0; int _currentvalue; bool mupdating = false; void start () { ValueText = GetComponent<UILabel> (); } //starts playing animation public void play (int _startvalue, int _finalvalue) { if (_startvalue == _finalvalue) return; mstartvalue = _ startvalue; mfinalvalue = _finalvalue; mNumUpdateTime = 0; mUpdating = true; } int CurrentValue { get { return _currentvalue ; } set { _CurrentValue = value; Valuetext.text = _curRentvalue+ ""; //string. Format ("{0:n0}", value); } } void update () { if (mupdating) { mNumUpdateTime += Time.deltaTime; if (mnumupdatetime >= manimtotaltime) { CurrentValue = mFinalValue; mUpdating = false; } else { currentvalue = t_getlocomotorvalue (mstartvalue, mfinalvalue, mnumupdatetime / This.manimtotaltime); } } } //displays the current values according to the scale private int t_getlocomotorvalue (Int p_startvalue, int p_endvalue, float p_ratio) { int returnvalue; if (p_ratio <= 0) { Returnvalue = p_startvalue; } else if (p_ RATIO&NBSP;>=&NBSP;1) { returnValue = p_EndValue; } else { returnValue = (int) (p _startvalue + (p_endvalue - p_startvalue) * p_ratio); } return returnValue; }}//How to use //void playnumberanamiaton (int nowamount, int oldamount, Uilabel target) // { // if ( Nowamount - oldamount > 0) // { // cclientapp.get (). Getuimgr (). Setpropchangelab (target.gameobject, Nowamount - oldamount, true); // } // else if (nowamount - oldamount < 0) { // cclientapp.get (). Getuimgr (). Setpropchangelab (target.gameobject, nowamount - Oldamount, false); // } // //Play Animation // numberanimation numanim = target. Getcomponent<numberanimation> (); // if (numAnim == null) // numanim = Target.gameobject.addcomponent<numberanimation> (); // Numanim.play (oldamount, nowamount); // oldamount = nowamount; // }
Unity Coin Flip Effect