- Home /
Printing text one by one, and changing text colors using Markup
I have a List of strings (which is the set of lines of a character). Every time the next button is pressed, I go to the next line in that list.
I am using this code right here to print each character one by one for my Dialogue system.
List<string> msg;
public IEnumerator TypeIn(int txtIndex)
{
yield return new WaitForSeconds(startDelay);
for (int i = 0; i <= msg[txtIndex].Length; i++)
{
textComp.text = msg[txtIndex].Substring(0, i);
yield return new WaitForSeconds(typeDelay);
if (i >= msg[txtIndex].Length)
{
isFinishedTyping = true;
// I need to know if it has finished printing one line
}
}
}
However, I'm trying to modify the code above to fit my needs. I would like to use Markup system to change the color of some the words. But the whole tag needs to be printed out completely before taking effect. I thought I could probably filter out the tag symbols, and to not print them when detected, I believe there is a way to do that with C# strings. I'm thinking of strings.split or something similar, but I'm not sure how to apply it. I don't have this much experience with strings so I'm doing some trial and error.
Can anyone tell me the most appropriate way to do this?
This was my third version of code, and still isn't working so I've decided to ask help.
public IEnumerator TypeIn(int txtIndex)
{
yield return new WaitForSeconds(startDelay);
bool markup = false, markupstarted = false;
string str_markup = "";
foreach(char c in msg[txtIndex])
{
if(c.ToString() == "<")
{
markup = true;
markupstarted = true;
}
else if(c.ToString() == ">")
{
markup = false;
}
else
{
if(markupstarted)
{
if(markup)
{
str_markup += c;
}
else
{
str_markup += c;
textComp.text += str_markup;
markupstarted = false;
}
}
else
{
textComp.text += c;
}
}
yield return new WaitForSeconds(startDelay);
}
//textComp.text = msg[txtIndex].Substring(0, i);
//yield return new WaitForSeconds(typeDelay);
//
// if (i >= msg[txtIndex].Length)
// {
// isFinishedTyping = true;
// }
}
Thank you so much for your help :(