using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class Counting : MonoBehaviour { public TextMeshProUGUI tmpScore; public Text txtScore; bool PLAY = false; public SoundPlayer spCounting; [Space(10)] public AnimationCurve curve; public float duration = 1f; [OnlyRead] public float tick = 0.1f; [Space(10)] [OnlyRead] public int value; [Space(10)] public int add = 100; public void Redraw() { if (tmpScore != null) tmpScore.text = $"{value}"; if (txtScore != null) txtScore.text = $"{value}"; //txtScore.text = value == 0 ? "0" : $"{value:#,###}"; } float timeSum = 0; void Play() { timeSum += tick; int add = (int)((valueEnd - valueStart) * curve.Evaluate(timeSum / duration)); if (timeSum < duration) { value = valueStart + add; if(spCounting != null && 0 < add && PLAY) SoundManager.Instance.EffectPlay(spCounting.gameObject); } else { value = valueEnd; valueEnd = 0; CancelInvoke(); } Redraw(); } int valueStart = 0; int valueEnd = 0; public void OnInitialized(int add, int cntDestroy, bool INIT = false, bool SOUND = false) { CancelInvoke(); if(INIT) { value = 0; Redraw(); return; } PLAY = SOUND; timeSum = 0; valueStart = value; if (valueEnd == 0) valueEnd = value + add; else valueEnd += add; tick = Time.deltaTime / duration; InvokeRepeating("Play", tick, tick); } }