Unity Coin Flip Effect

Source: Internet
Author: User

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;&GT;=&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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.