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