- Home /
Having trouble with GUI box
Hey Guys, I am having trouble with displaying text, I am using text from a text file.I just want it to display the text at the bottom middle of the screen. Please have a look, any help is appreciated.
using UnityEngine;
using System.Collections;
public class npc_Dialog : MonoBehaviour {
public TextAsset textFile;
string[] dialogLines;
bool bShowGUI = false;
string dialog;
// Use this for initialization
void Start () {
if(textFile != null){
dialogLines = ( textFile.text.Split( '\n' ) );
}
}
void OnTriggerEnter2D (Collider2D other){
bShowGUI = true;
}
void OnTriggerExit2D (Collider2D other) {
bShowGUI = false;
}
void OnGUI(){
if (bShowGUI) {
if (GUI.Button (new Rect (10, 10, 100, 30), "Investigate")) {
Debug.Log ("You pressed the button");
Debug.Log(dialogLines[0]);
GUI.Box(new Rect (30, 30, 100, 100), dialogLines[0]);
}
}
}
}
Comment
so whats the problem here? please elaborate it. as per my assumption you have read the file but it displays only first line till '\n' ( line end ) and you want to display complete file in Box right?
Your answer
![](https://koobas.hobune.stream/wayback/20220613200835im_/https://answers.unity.com/themes/thub/images/avi.jpg)