Hello everybody,
I have a problem with a GUI.Label script. My purpose is creating a script that changes the content of a label text of a different script. I followed this question (http://forum.unity3d.com/threads/11462-Changing-GUI.Label-text) but I realised the problem is in the main script.
var textLabel : String = "Initial text";
function OnGUI (){
GUI.Box(Rect(Screen.width/2 - 200,Screen.height/2 - 200,400,400),"");
GUI.Label(Rect(Screen.width/2 - 190,Screen.height/2 - 170,400,400),textLabel);
}
Once I write the initial text and test in scene I can’t change it after from the script but in the Inspector.
And…well, when I try to do the other script I can’t
Sorry for my bad english. If I don’t explain correctly tell.
Thanks!
It is by definition that you may not change a public variable contents from within the script, once it is attached as a component.
var textLabel : String = "Initial text";
is the same as writing:
public var textLabel : String = "Initial text";
This is what exposes the ‘textLabel’ variable to the inspector.
When you change the content from the script, you change the default value, so that change will show on any new placing of the script as a component on game objects, but not on existing ones.
Change the content in the inspector or at run time by code - does change the content.
You should have no problem changing the content from another script.
Maybe post what you are doing from that other script so I can have a look?
Thanks, so you mean that I can change the content in the inspector or with the script in playmode?
Also thanks for the description of “public var” 
the other script is:
well, firstly I have this script called “HUD”:
#pragma strict
public var textLabel : String =
“Initial text”;
function OnGUI (){
GUI.Box(Rect(10,10,140,20),"");
GUI.Label(Rect(10,10,140,20),textLabel);
}
And the other script called “changeLabel”:
public function changeLabelText () :
void { var myObject : GameObject =
GameObject.Find(EntornoHUD);
myObject.GetComponent(HUD).textLabel
= “Traca traca tá ta”; }
both are inside the same GameObject called “EntornoHUD” but the console says that:
Assets/Scripts/changeLabel.js(12,53): BCE0005: Unknown identifier: ‘EntornoHUD’.
I think I’m missing something very important
Thanks!