Skip to content

Instantly share code, notes, and snippets.

@taross-f
Created April 28, 2017 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taross-f/71bb39ce89840c3f1df3051446ee72f6 to your computer and use it in GitHub Desktop.
Save taross-f/71bb39ce89840c3f1df3051446ee72f6 to your computer and use it in GitHub Desktop.
AnimationText.cs
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