Last active
February 1, 2024 12:42
-
-
Save jade-itworkswhy/af2f0c91a4f25e83b25f7cff6d52c0ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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