How do I make an external text document show only between certain lines in UI Text
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 ('\n'));
}
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();
}
}
Answer by toddisarockstar · Aug 21, 2016 at 11:39 PM
seems you could make things easier by just putting your own split character in your text doc.
BILLY THE KIDD%
REAL NAME WILLIAM BONNEY%
BORN: 1860%
DIED: JULY 13, 1881
and split like this:
factoidLines = factoidText.text.Split("%"[0]);
Thanks but I think you miss understood my question. Splitting the text is not the issue.... it's getting the UI text to display between a line range, like say if you had a block of text and you just wanted to display a few lines from that block or paragraph of text.
The idea is to try and use one external text document to draw information from.
Your answer
Follow this Question
Related Questions
How To Load TTF Font From External File 0 Answers
Display CPU usage on a UI Slider or Text 1 Answer
How to properly display debug messages on UI 0 Answers
Updated with UI text element not correct (same frame) 0 Answers
Score UI per player 1 Answer