kyasul
November 6, 2012, 12:21am
1
My code is simple enough:
var fuel = 100;
function Update () {
var strFuel = fuel.ToString();
guiText.text(strFuel);
}
However, for some reason, i get the following error:
So what am i missing? Because i don’t suspect i’m converting the integer incorrectly.
typane
November 6, 2012, 12:32am
2
kyasul:
My code is simple enough:
var fuel = 100;
function Update () {
var strFuel = fuel.ToString();
guiText.text(strFuel);
}
However, for some reason, i get the following error:
So what am i missing? Because i don’t suspect i’m converting the integer incorrectly.
var fuel : int = 100;
function OnGUI()
{
var strFuel = fuel.ToString();
this.guiText.text = strFuel;
}
Works in Update as well, this is impractical and would not be efficient to change something as drastic as this but for experimental purposes you can see what is happening
guiText.text is a variable, not a method. You must assign the value with the = operator.
guiText.text = strFuel;
or more directly
guiText.text = fuel.ToString();
typane:
function OnGUI()
{
var strFuel = fuel.ToString();
this.guiText.text = strFuel;
}
Works in Update as well, this is impractical and would not be efficient to change something as drastic as this but for experimental purposes you can see what is happening
Should not be in OnGUI in any case. OnGUI is only for GUI or GUILayout code. Also you can leave out “this.”. Just guiText.text is fine.
–Eric