Skip to content

Instantly share code, notes, and snippets.

@jade-itworkswhy
Last active February 1, 2024 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jade-itworkswhy/af2f0c91a4f25e83b25f7cff6d52c0ab to your computer and use it in GitHub Desktop.
Save jade-itworkswhy/af2f0c91a4f25e83b25f7cff6d52c0ab 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