Unity3d Dotween Animation for digital change animation

Source: Internet
Author: User

In the game, often there is the need to increase the number from 1 to a value of N, and the animation from 1 to the value of n changes in the process, every change, there is animation, but often this animation is not over, the next animation is coming. To solve this problem, you can use the following idea.

That is, the animation is not finished, the next animation can not be broadcast, after an animation, and then the next. See the code below.

usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingDG. tweening; Public classIngamefloweritem:monobehaviour { Public UINTm_id;  Public stringM_sendername ="";  Public intM_num =0;//the number of flowers that have been sent     PublicText M_nametext;  PublicText M_numtext;  Public floatM_removetime =5f;    Tweener M_tweener; Private intM_tweennum =0; Private BOOLFlag =false;  Public voidShow () {gameobject.setactive (true); M_nametext.text=M_sendername; if(M_num <=5) {M_numtext.text=m_num.tostring (); }         This. Invoke ("removeself", M_removetime); }     Public voidAddnum () { This. Cancelinvoke ("removeself");  This. Invoke ("removeself", M_removetime); if(M_num >5)//working with text animations{m_tweennum++; }        Else{m_num++; }    }    voidDotween () {if(M_tweennum <=0) {flag=false; return; }        if(M_tweener! =NULL&&m_tweener.isplaying ()) {            return; } M_tweener= M_NumText.transform.DOScale (3f,0.25f). Setease (Ease.inback). OnComplete (() ={M_numtext.text= (++m_num).            ToString (); M_NumText.transform.DOScale (1f,0.25f). OnComplete (() ={m_tweennum--;            Dotween ();        });    }); }    //Update is called once per frame    voidUpdate () {if(M_tweennum >0&&!flag) {Flag=true;        Dotween (); }    }    voidondisable () {M_tweener.kill (); }     Public voidInitData (UINTIdstringSenderName,intnum) {m_id=ID; M_sendername=SenderName; M_num=num; }     Public voidremoveself () {InGameFlowerPanel.Inst.ClearFlowerItem (m_id);  This. Cancelinvoke ("removeself");    Destroy (Gameobject); }    }

Unity3d Dotween Animation for digital change animation

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.