I have a script I am trying to use an external text document (.txt) to display UI text on a canvas panel, but the tricky part is that for each public void called upon I want each one to display the text from the .txt document in blocks, for example:
Display these lines of text from the text document:
BILLY THE KIDD
REAL NAME WILLIAM BONNEY
BORN: 1860
DIED: JULY 13, 1881
And then be able to call on another section of text from the .txt document.
This is what i’m using but I’m not understanding the array usage correctly:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class FactoidManager : MonoBehaviour {
public Text factoidScreenText;
public TextAsset factoidText;
public string[] factoidLines;
public int startLine;
public int endLine;
void Start(){
if (factoidText != null) {
factoidLines = (factoidText.text.Split ('
'));
}
if (endLine == 0) {
endLine = factoidLines.Length - 1;
}
}
//Factoid Calls
public void GoFactoid01(){
factoidScreenText.text = factoidLines[startLine]; //NEEDS to Display multiple lines from the .txt doc
StartCoroutine(LoadFactoid01());
}
//Factoid Calls
IEnumerator LoadFactoid01(){
yield return new WaitForSeconds(1.5f); // wait time
MasterPanelManager mpm = FindObjectOfType<MasterPanelManager>();
mpm.EnableFactoidPanel();
CameraSwitcher cs18 = FindObjectOfType<CameraSwitcher>();
cs18.EnableCamera18();
yield return new WaitForSeconds(15.5f); // wait time
MasterPanelManager ebd = FindObjectOfType<MasterPanelManager>();
ebd.DisableFactoidPanel();
CameraSwitcher csdef = FindObjectOfType<CameraSwitcher>();
csdef.CameraDefault();
}
}