- Home /
Check when text is done being printed?
Hey! So I have this very simple code printing the text contained in a .txt file to a UI text field, one character at a time. Obviously, this takes a small amount of time. What I'd like to do is check (probably in Update to test it out) when this file is done being printed to my game's UI text element. Can anyone give me a hand with this? Here's the code so far: public string textFile; public Text txtContents; float textSpeed = .02f;
// Use this for initialization
void Start () {
StartCoroutine("RunText");
}
// Update is called once per frame
void Update () {
}
IEnumerator RunText()
{
var stringBuilder = new StringBuilder();
TextAsset txtAssets = (TextAsset)Resources.Load(textFile);
foreach (char c in txtAssets.text)
{
stringBuilder.Append(c);
txtContents.text = stringBuilder.ToString();
yield return new WaitForSeconds(textSpeed);
}
}
}
Answer by bennett_apps · Aug 15, 2018 at 03:11 AM
after the foreach loop, just set a bool to true!
// Use this for initialization
void Start () {
StartCoroutine("RunText");
}
// Update is called once per frame
void Update () {
}
IEnumerator RunText()
{
var stringBuilder = new StringBuilder();
TextAsset txtAssets = (TextAsset)Resources.Load(textFile);
foreach (char c in txtAssets.text)
{
stringBuilder.Append(c);
txtContents.text = stringBuilder.ToString();
yield return new WaitForSeconds(textSpeed);
}
someBool = true;
}
Your answer
Follow this Question
Related Questions
Why the text and the UI code is can't applying 0 Answers
UI Text compression on android 1 Answer
Render Debug.Log as UI Text 2 Answers
What's your equivalent of old GUIStyle ? 0 Answers
Canvas is flipping, 2D game 0 Answers