Text box not displaying a character split string generated at runtime
I have a text box on a scene in unity. At the point with the issue, the text box already has a few separate lines of text.
The script is as follows: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System;
public class GameEngine : MonoBehaviour {
//Game level variables:
public bool TutorialDone = false;
public int TutorialCount = 0;
bool isticking = false;
Text outputtext;
// Use this for initialization
void Start () {
outputtext = GameObject.Find("ConsoleOutputScroll/Viewport/Output").GetComponent<Text>();
}
// Update is called once per frame
void Update () {
}
//Process inputted text and splits into commands, validation etc.
public void processtext(string inputstring)
{
if(inputstring == "")
{
commandin("blank");
return;
}
commandin("something");
return;
}
//Process any commands supplied, apply these to game stages
public void commandin(string commandtype)
{
if(TutorialDone == false)
{
tutorialrun();
return;
}
}
//Tutorial procedure
public void tutorialrun()
{
switch (TutorialCount)
{
case 0:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 1:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 2:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 3:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 4:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 5:
TutorialCount++;
outputnewline("***CRITICAL SYSTEM FAILURE*** Press any key to exit...");
break;
case 6:
TutorialCount++;
tickertypenewline("ESTABLISHING CONNECTION...");
break;
}
}
//Appends to the console output on a new line
public void outputnewline(string inputstring)
{
string Temp;
Temp = outputtext.text + inputstring + Environment.NewLine;
outputtext.text = Temp;
}
//Clears output and adds new text
public void outputclear(string inputstring)
{
outputtext.text = inputstring + Environment.NewLine;
}
//Typewriter style text addition on a new line
public void tickertypenewline(string inputstring)
{
//Exit if we are already ticking
if (isticking)
{
return;
}
isticking = true;
StartCoroutine(tickertypeco(inputstring));
}
//Typewriter style text after clearing output
public void tickertypeclear(string inputstring)
{
outputtext.text = "";
StartCoroutine(tickertypeco(inputstring));
}
//Typewriter generator
IEnumerator tickertypeco(string inputstring)
{
//outputtext.text = "sugar";
WaitForSeconds waitTime = new WaitForSeconds(0.125f);
foreach (char c in inputstring)
{
string temp = outputtext.text + c.ToString();
outputtext.text = temp;
yield return waitTime;
}
isticking = false;
}
The functions tickertypenewline and tickertypeclear don't appear to do anything. If I clear the text box beforehand it doesn't appear to do anything. However if I clear and then add a random string of 3 characters or more without any new lines or spaces, it then behaves correctly. The outcome should be a typed effect on the string as it enters the text box.
I have tried taking out the code pertaining to those particular functions, disabling all other scripts and placing it to be run on it's own automatically and it works fine.
Can't seem to work out where the fault is with this.
Can someone help please? :)
I was unable to reproduce the bug you described. Here is the unity package containing the scene I used to test it. I tried running processText a few times and running tickertypeclear as well. The only bug I found was tickertypeclear being called multiple times before one finishes makes both coroutines type at the same time. Please let me know if I missed the problem!
Your answer
Follow this Question
Related Questions
Rubik's Cube scramble algorithm 0 Answers
Making a in editor public writing prompt 0 Answers
Making a RPG video Tutorial question 1 Answer