Unity UGUI Text文本动起来

原文: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();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/kuilaurence/article/details/120325276