When I run the following script:
static var SCORE : int = 0;
function OnGUI ()
{
GUI.Label (Rect (10, 10, 100, 20), SCORE);
}
I get this error:
Assets/MeMadeStuff/ScoreBoard.js(5,19): BCE0023: No appropriate version of 'UnityEngine.GUI.Label' for the argument list '(UnityEngine.Rect, int)' was found.
And my score of 0 does not display.
I do not understand why I cannot display SCORE, when I change the script to read:
static var SCORE : int = 0;
function OnGUI ()
{
GUI.Label (Rect (10, 10, 100, 20), "hello");
}
The script properly displays "hello"
What am I doing wrong that is preventing me from being able to have my static var SCORE displayed on my screen?
If you look at the docs for GUI.Label, you see this:
static function Label (position : Rect, text : string) : void
static function Label (position : Rect, image : Texture) : void
static function Label (position : Rect, content : GUIContent) : void
(Plus another version of the same with a GUIStyle parameter.) As you can see, you can only display a string, a texture, or GUIContent. In order to display an int, you have to convert it to a string, such as with ToString().
system
3
I did a label with ints in it without having to use toString() before. Maybe it's because for the text parameter of Label i put something like `"int : " + myInt`