I am trying to make an RPG style dialog script

So I am making a script where there is a text area at the bottom of the screen and every time you click it displays the next message. Here is my code

var DialogText = new Array();

private var number = 0;

function Start () {

	DialogText.length = 19;

}

function Update () {

}



function OnGUI () {
	 if (Input.GetButton("Fire1")) {
	 	GUI.TextArea (Rect (Screen.width / 2, Screen.height / 8, 100, 30), DialogText[number]);
	 	number += 1;
	 }
}

The problem I am running into is that when I attach it to my camera to use it, I can’t edit the DialogText variable in the unity editor. I also have a problem that there is no text being displayed.

To simply get it to show in the editor, all you have to do is this :slight_smile:

var DialogText = new String[19];
 
private var number = 0;
 
function OnGUI () {
     if (Input.GetButton("Fire1")) {
       GUI.TextArea (Rect (Screen.width / 2, Screen.height / 8, 100, 30), DialogText[number]);
       number += 1;
     }
}

I’m guessing about your intent. Try restructuring your code to this:

function OnGUI () {
	GUI.TextArea (Rect (Screen.width / 2, Screen.height / 8, 100, 30), DialogText[number]);
     if (Input.GetButtonDown("Fire1")) {
         number += 1;
     }
}

First, I replaced your GetButton() with GetButtonDown() That way number will only be increment during the frame the “Fire1” button is pressed. In addition I pulled GUI.TextArea() call outside of your if statement.