Created
January 27, 2018 13:26
-
-
Save miguelSantirso/044de7db249c867c3ffff672668fa688 to your computer and use it in GitHub Desktop.
Naive text reveal, discarding whitespaces
This file contains hidden or 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
public class TextRevealer : MonoBehaviour { | |
public Text text; | |
void Start () { | |
StartCoroutine(RevealText()); | |
} | |
IEnumerator RevealText() { | |
var originalString = text.text; | |
text.text = ""; | |
var numCharsRevealed = 0; | |
while (numCharsRevealed < originalString.Length) | |
{ | |
while (originalString[numCharsRevealed] == ' ') | |
++numCharsRevealed; | |
++numCharsRevealed; | |
text.text = originalString.Substring(0, numCharsRevealed); | |
yield return new WaitForSeconds(0.07f); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment