DynamicText.cs 869 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. using TMPro;
  6. public class DynamicText : MonoBehaviour
  7. {
  8. public TextMeshPro text;
  9. private Sequence mScoreSequence;
  10. private float mOldScore = 0;
  11. private float newScore = 0;
  12. public float num;
  13. void Awake()
  14. {
  15. mScoreSequence = DOTween.Sequence();
  16. mScoreSequence.SetAutoKill(false);
  17. }
  18. private void OnEnable()
  19. {
  20. newScore = num;
  21. DynamicNum();
  22. }
  23. void Start()
  24. {
  25. }
  26. public void DynamicNum()
  27. {
  28. mScoreSequence.Append(DOTween.To(delegate (float value) {
  29. var temp = Math.Floor(value);
  30. text.text = temp + "";
  31. }, mOldScore, newScore, 2));
  32. mOldScore = newScore;
  33. }
  34. private void OnDisable()
  35. {
  36. mOldScore = 0;
  37. newScore = 0;
  38. }
  39. }