Hi!
I’m working on a dialogue system and am having some frustrating trouble with String.Remove. I got it working fine in one part of the script, but now that I’m trying to utilize it again it won’t work at all. All ‘┐’ characters are supposed to be removed when clicking Z to make the text scroll by instantly. It works when the text scrolls by with normal speed in the coroutine, but not here. I’ve put Debug.Log(a); to check if it actually catches every instance of the ‘┐’ character, and it does!
I’m sure there’s something crucial I’m not seeing and I’d really appreciate any help I could get. Will provide more details if needed.
if (Input.GetKeyDown(KeyCode.Z))
{
if (!isTyping)
{
currentLine++;
if (currentLine > endAtLine)
{
DisableTextBox();
}
else
{
StartCoroutine(TextScroll(textLines[currentLine]));
}
}
else if (isTyping && !cancelTyping)
{
int i = 0;
string lineOfText = textLines[currentLine];
while (i < lineOfText.Length)
{
char a = lineOfText.ToCharArray()*;*
i++;
if (a == ‘┐’)
{
Debug.Log(a);
lineOfText = lineOfText.Remove(i, 1);
}
}
cancelTyping = true;
}
}
Below is an example of String.Remove working in the same script.
private IEnumerator TextScroll (string lineOfText)
{
int letter = 0;
int i = 0;
theText.text = “”;
isTyping = true;
cancelTyping = false;
while (isTyping && !cancelTyping && (letter < lineOfText.Length - 1))
{
char a = lineOfText.ToCharArray();
i++;
if (a == ‘┐’)
{
lineOfText = lineOfText.Remove(i - 1, 1);
yield return new WaitForSeconds(0.5f);
}
theText.text += lineOfText[letter];
letter++;
if ((a != ‘,’ && a != ‘.’ && a != ‘!’ && a != ‘?’ && a != ‘┐’) || ((a == ‘.’ || (a == ‘!’) || (a == ‘?’)) && i == (lineOfText.Length - 1)))
{
yield return new WaitForSeconds(typeSpeed);
}
else if (a == ‘,’)
{
yield return new WaitForSeconds(0.25f);
}
else if (a == ‘.’ || (a == ‘!’) || (a == ‘?’))
{
yield return new WaitForSeconds(0.5f);
}
}
theText.text = lineOfText;
isTyping = false;
cancelTyping = false;
}