- Home /
Set guiText
Hi, I have 2 scripts, one has a variable "monthn" and Iam adding one to that variable every second. The other script is supposed to take the variable from the first script and set the text of a gui to the value of that variable, but instead it just disappears immediately. Script one: var monthn : int;
function Start () {
InvokeRepeating("TimeUpdate", 1.0, 1.0);
}
function TimeUpdate () {
monthn += 1;
Debug.Log (monthn);
}
Script two:
function Update () {
guiText.text = Time.monthn;
}
Comment
Answer by justin_iSO · Jan 09, 2013 at 07:54 PM
If you are set on this structure then something like this works.
//TimeScript.js
public static var monthn : int;
function Start () {
InvokeRepeating("TimeUpdate", 1.0, 1.0);
}
function TimeUpdate () {
monthn += 1;
Debug.Log (monthn);
}
Script Two
//TextScript.js
//Placed on the GUIText you are using
function Update () {
this.guiText.text = TimeSript.monthn.ToString();
}
thanks for your help but it did not work, I made a single script ins$$anonymous$$d of the two and everything seems to work. Thanks anyway.