- Home /
Simple Point system
I'm doing a point system. All im simply wondering is how to convert a int into a string so I wont get a stupid error message. Basicly what im trying to achieve is to take the current score and make the GUItext display it.
So here's basicly my code.
Can see anything I'm already doing wrong.
static var score = 0;
var scoreDisplay: GUIText;
function Update(){
scoreDisplay.text = score;
}
Answer by Eric5h5 · May 26, 2011 at 10:45 PM
scoreDisplay.text = score.ToString();
There's no need to have that in Update, though. That means you're constantly updating scoreDisplay.text every frame even when the score hasn't changed. Make a function that you call when the score changes, instead.
Answer by CarlLawl · May 26, 2011 at 10:36 PM
Use parseint or tostring, check it out in the unity scripting ref i hope this helps!
Answer by aldonaletto · May 26, 2011 at 10:37 PM
You should add some text to the score value (even an empty string) - javascript will convert the score to string automatically:
scoreDisplay.text = ""+score;
You should usually stay away from string concatenation like that. It's more efficient to use ToString().