原文:https://blog.csdn.net/qq258456qq/article/details/104658589
代码:
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public class NumberMove : MonoBehaviour
{
public Text text;
private Sequence mScoreSequence;
private int mOldScore = 0;
private int newScore = 0;
void Awake()
{
mScoreSequence = DOTween.Sequence();
mScoreSequence.SetAutoKill(false);
}
void Start()
{
}
void DigitalAnimation()
{
mScoreSequence.Append(DOTween.To(delegate (float value)
{
var temp = Mathf.Floor(value);
text.text = temp + "";
text.color = Color.red;
text.DOColor(Color.black, 1f);
}, mOldScore, newScore, 0.4f));
mOldScore = newScore;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
newScore += 1234;
DigitalAnimation();
}
}
}