Skip to content

Instantly share code, notes, and snippets.

@jadepark-dev
Created August 6, 2020 09:17
Show Gist options
  • Save jadepark-dev/6e522acb18833d025316916c4114f913 to your computer and use it in GitHub Desktop.
Save jadepark-dev/6e522acb18833d025316916c4114f913 to your computer and use it in GitHub Desktop.
#region counting functions
public void TextCountTo (int target, Text text) {
if(countingCoroutine != null)
StopCoroutine("CountTo");
countingCoroutine = StartCoroutine(CountTo(target, text));
}
IEnumerator CountTo (int target, Text countText) {
int start;
int.TryParse(countText.text, out start);
for (float timer = 0; timer < countingDuration; timer += Time.deltaTime) {
float progress = timer / countingDuration;
countText.text = ((int)Mathf.Lerp (start, target, progress)).ToString();
yield return null;
}
countText.text = target.ToString();
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment