- Home /
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.
Answer by AT-Brackeys · Jan 26, 2013 at 01:48 AM
To simply get it to show in the editor, all you have to do is this :)
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;
}
}
Answer by robertbu · Jan 26, 2013 at 02:54 AM
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.
Okay, this works great except for one part. I want after 11 messages go by, for a text box to appear so the user can input their name. How would I go about doing this so that the textarea is cleared from the screen and replaced with a textfield until the user presses enter and then the info inserted into the text field is stored in a variable then the messages will reappear at the next number (12).
(Sorry if this is super confusing, I'm working on a big project right now and my brain is overloaded and tired :P)
OnGUI gets executed each frame, so your GUI.TextArea() is gettting put up each frame. If you don't make the TextArea() call, then the text won't be displayed. As for an edit field, I believe you are looking for GUI.TextField(). You may also want to put up a submit button at the same time (GUI.Button).
Your answer

Follow this Question
Related Questions
RPG turns system - arranging turns freezes up 1 Answer
How to make a cutscene like RPG Games 1 Answer
Prevent IOS keyboard from showing 0 Answers
Toolbar Selection 0 Answers
GUI Text field? How do I make the text so it goes on more then one line? 1 Answer