- Home /
How to create GUI text box and update from script.
I'm having some trouble working this out.
I'm creating a 3d mapping program and want to have an info box on the right that is updated depending on what I click on but I must be missing something in how I access the text content of the GUI control.
Can someone point me in the right direction.
So I have the following TextField entry:
GUI.TextField(new Rect(Screen.width-200,0,200,Screen.height-40),"Info");
How can I then either assign and object to access it publicly or name it to access the text field and update?
I'd really like to understand how to access this as I use GameObject.FindWithTag for other objects, so can I add a tag to a GUI element and access it that way?
Answer by dorpeleg · Sep 04, 2014 at 09:27 AM
If it's an info box, I'm guessing you don't want the user to be able to edit it right?
Use GUI.Label to display text the user can't edit.
In order to change the string during runtime, you will have to make a var.
Something like this:
public string InfoText;
void OnGUI()
{
GUI.Label(new Rect(Screen.width-200,0,200,Screen.height-40), InfoText);
}
Then, you can change the InfoText from anywhere you want and it will update automatically.
Okay, I have done this and then attempt to access from a differnet script which just tells me that it does not exist in the currrent context.
I've changed to using a GUIText opject now as this seems to be less complicated to impliment what I want.
@maaarcooose you probably doing something else wrong...
But If you went to a different solution that works for you, please close the question
Your answer
