Issues with Scrolling Dialogue (repeating characters when printing text)
Hello, I have been following this tutorial, in an attempt to get a basic dialogue box system working for my game. While I have it working just fine, in some cases when attempting to access the dialogue box this will occur:
This problem will only present itself on the first line of the text file, and when left alone for a small amount of time will eventually fix itself, but the same letter doubling will occur when attempting to initiate the conversation.
These are the scripts that manage the dialogue action: public class TextboxManager : MonoBehaviour {
public GameObject textbox;
public Text theText;
public TextAsset textFile;
public string[] textLines;
public int currentLine, endLine;
PlayerMovement playermovement;
public bool active,freezePlayer,buttonPress;
bool waitforpress;
private bool isTyping = false;
private bool cancelTyping = false;
public float typeSpeed;
// Use this for initialization
void Start () {
playermovement = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMovement>();
if (textFile != null)
{
textLines = (theText.text.Split('\n'));
}
if(endLine == 0)
{
endLine = textLines.Length - 1;
}
if (active)
{
EnableText();
}
else
{
DisableText();
}
}
// Update is called once per frame
void Update ()
{
if (!active)
{
return;
}
//theText.text = textLines[currentLine];
if (Input.GetKeyDown(KeyCode.E))
{
if (!isTyping) {
currentLine += 1;
if (currentLine > endLine) {
DisableText ();
}
else {
StartCoroutine (TextScroll (textLines[currentLine]));
}
}
//else if scrolling, and isnt already cancelled, cancel typing.
else if(isTyping && !cancelTyping){
cancelTyping = true;
}
}
}
private IEnumerator TextScroll (string lineOfText) {
int letter = 0;
theText.text = "";
isTyping = true;
cancelTyping = false;
while (isTyping && !cancelTyping && (letter < lineOfText.Length - 1)) {
theText.text += lineOfText [letter];
letter += 1;
Debug.Log(theText.text);
yield return new WaitForSeconds (typeSpeed);
Debug.Log(theText.text);
}
//if cancelled:
theText.text = lineOfText;
isTyping = false;
cancelTyping = false;
}
public void EnableText()
{
GenericInteraction.engaged = true;
textbox.SetActive(true);
active = true;
if (freezePlayer)
{
playermovement.canMove = false;
}
StartCoroutine (TextScroll (textLines[currentLine]));
}
public void DisableText()
{
GenericInteraction.engaged = false;
textbox.SetActive(false);
active = false;
playermovement.canMove = true;
}
public void ReloadScript(TextAsset theText)
{
if(theText != null)
{
textLines = new string[1];
textLines = (theText.text.Split('\n'));
}
}
}
And the following Script is what activates particular text files attached to different characters
public class ActivateTextAtLine : MonoBehaviour{
public void ActivateCurrentFile(TextAsset theText,int startLine,int endLine,bool freeze,TextboxManager textBox)
{
textBox.ReloadScript(theText);
textBox.currentLine = startLine;
textBox.endLine = endLine;
textBox.freezePlayer = freeze;
textBox.EnableText();
}
}
I can see that the letters seem to be doubling up when printing which would make me think that some how the TextScroll coroutine is being run twice when being activated double printing each pair of letters before eventually writing itself, how this would be solved is beyond me currently so any input would be most appreciated.
Your answer
Follow this Question
Related Questions
Making texts look smooth good and not pixel crisp no matter their size with TMP & custom fonts 0 Answers
Display rigidbody speed to a world space canvas text 2 Answers
Gui Text won't turn off 0 Answers
Label and line renderer not showing 0 Answers
Mobile game lags when text mesh and gui text updating 0 Answers