Unity 2D - Text UI and Textbox scripting issue - HELP ASAP!

Hi, I’m new to Unity, coding and game development.
I was trying to make a textbox system, and something isn’t working, and it’s not allowing my .txt file lines to be written in the Text UI object. It’s just displaying default text, and not displaying what I wanted… Please help? :slight_smile:

I cannot figure out what is wrong… :frowning:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TextBoxManager : MonoBehaviour {

	public GameObject textBox;

	public Text theText;

	public TextAsset textFile;
	public string[] textLines;

	public int currentLine;
	public int endAtLine;

	public PlayerController player;

	// Use this for initialization
	void Start () 
		player = FindObjectOfType<PlayerController>();

		if (textFile != null) 
			textLines = (textFile.text.Split('



		if(endAtLine == 0) 
			endAtLine = textLines.Length - 1;



	void update()

		theText.text = textLines[currentLine];

		if (Input.GetKeyDown (KeyCode.Return)) 
			currentLine += 1;


I would suggest some improvements of your code:

  • assign a start value to currentLine before you use it the first time
  • Add theText.text = textLines[currentLine] into the if statement. This avoids adding the text each frame
  • Use Input.GetKeyUp to avoid going through all the lines real quick when you are holding the return key to long down. I guess you want to move 1 further only ones per key push
  • add code to limit currentLine to the maximum number of lines available.
  • Use Update instead of update as it must be used with a capital U.

Please refere this link:

I think it will solve your problem!