- Home /
Create new GUI TextArea on click
I want to create TextArea every time I click on the button. In this code, when I click for the first time, it does create two new textarea, but when I click again, it changes their Y instead of creating two new ones. What do I have to change to create new GUI instead of modifying them?
#pragma strict
var submit = false;
var x = 10;
var y = 10;
var a = 100;
function Start () {
}
function Update () {
}
function OnGUI(){
if(GUI.Button(Rect(10,500,50,50),"Click")){
submit = true;
y+=y;
}
if(submit){
GUI.TextArea(Rect (x, y, a, a), " ", 20);
GUI.TextArea(Rect (x, y+a, a, a), " ", 20);
}
}
Answer by Slev · Sep 21, 2014 at 08:11 PM
Yes because each line is making a new text box. Instead what you want to do is something like:
if (GUI.Button(Rect(10,500,50,50), "Click")) {
num_boxes++;
}
And then use a loop or something to draw them. The better option might be to store each one in an Array or List of GUI.TextArea, that way they can be modified separately if you wish.
Since the TextArea doesn't actually return itself however, this could be problematic, you may need a Tuple style List of rectangles and strings for each box.
Edit: You may also wish to consider using Unity 4.6 Beta as it contains much better implementations of these things and may give you better results.