Created
April 28, 2017 05:24
-
-
Save taross-f/71bb39ce89840c3f1df3051446ee72f6 to your computer and use it in GitHub Desktop.
AnimationText.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DG.Tweening; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class AnimationText : MonoBehaviour | |
{ | |
Text _text; | |
void Awake() { _text = gameObject.GetComponent<Text>(); } | |
public void StartCountAnimation(int to, float duration = 0.4f) | |
{ | |
ulong _; | |
if (!ulong.TryParse(_text.text, out _)) StartFadeAnimation(to.ToString(), duration); | |
DOTween.To( | |
() => ulong.Parse(_text.text), | |
x => _text.text = ((int)x).ToString(), | |
to, | |
duration) | |
.SetEase(Ease.OutQuad) | |
.OnComplete(() => _text.text = to.ToString()); | |
} | |
public void StartFadeAnimation(string to, float duration = 0.4f) | |
{ | |
DOTween.Sequence() | |
.Append(_text.DOFade(0, duration / 2)) | |
.AppendCallback(() => _text.text = to) | |
.Append(_text.DOFade(1, duration / 2)) | |
.Play(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment