- Home /
Question by
Darkluca · Apr 11, 2021 at 09:19 PM ·
coroutinestringcoroutinesienumeratorstrings
Backspace typewriter effect
I did a typewriter effect. However, I would like to do a backspace effect where it would individually remove letters. I've tried so many things but I couldn't get it right. This is my current code:
IEnumerator PlayBookName()
{
bookNameString = "Witch of the South";
foreach (char c in bookNameString)
{
bookName.text += c;
yield return new WaitForSeconds(0.02f);
}
}
Comment
Best Answer
Answer by Hellium · Apr 11, 2021 at 10:05 PM
Code NOT tested
IEnumerator EraseBookName()
{
WaitForSeconds wait = new WaitForSeconds(0.02f);
while(bookName.text.Length > 0)
{
bookName.text = bookName.text.Substring(0, bookName.text.Length - 1);
yield return wait;
}
}
However, I would suggest using TextMeshPro's maxVisibleCharacters
instead (both for typing and erasing effects)
Your answer
Follow this Question
Related Questions
Make a function that can return string or IEnumerator 2 Answers
How do Coroutines behave with Triggers? 1 Answer
Coroutines IEnumerator not working as expected 2 Answers
Coroutines not passing yield 1 Answer
Collection Change During Iteration 0 Answers