- Home /
Question by
MashedzFruitz · Nov 08, 2011 at 10:44 AM ·
guiscorevarstatic-vars
Help! Why doesn't this work? GUI/Static vars Help! Javascript
This is my script, I'm getting errors. For some reason I only seem to get this error when I am using static vars rather than regular ones
static var score : int = 10;
function OnGUI()
{
GUI.Label(Rect(Screen.width/5-100,Screen.height/5-90,300,30), score);
}
Comment
Answer by Bunny83 · Nov 08, 2011 at 11:03 AM
Try this:
GUI.Label(Rect(Screen.width/5-100,Screen.height/5-90,300,30), score.ToString());
// or
GUI.Label(Rect(Screen.width/5-100,Screen.height/5-90,300,30), "" + score);
GUI.Label only accepts String (besides other specific objects), thus you must convert a numeric value to String before using it. score.ToString() does this conversion, as well as using the number in a string expression, like @Bunny83 did with ""+score (the compiler converts score to string automatically in this case)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Score Help (Im new) 1 Answer
Adding 1 point after collison 1 Answer
Score and gui help 1 Answer
1st time to use Unity can help me with this simple project? 0 Answers