Created
August 6, 2020 09:17
-
-
Save jadepark-dev/6e522acb18833d025316916c4114f913 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