- Home /
INCREASE SCORE MORE AND MORE?
So I have gotten my idea for my game, I want score to increase by 1 every 2 secs and to show the score in GUI Text but It ain't working! Help me? var pointscore: int=0; function Start () {
while(true){
pointscore++;
yield WaitForSeconds(2);
}
}
function OnGUI() {
GUI.Box(Rect(0,0,320,42), pointscore);
}
Answer by YoungDeveloper · Sep 29, 2013 at 10:29 AM
Sorting your code would be first step, and CAPS LOCK is not necessary.
I'm not a unityscript guy, but this should work.
var pointscore: int=0;
function Start(){
PointsCounter();
}
function PointsCounter(){
//infinite loop
for(;;){
yield WaitForSeconds(2);
pointscore++;
}
}
function OnGUI(){
GUI.Box(Rect(0,0,320,42), pointscore);
}
CAompiler error: Assets/SCORER.js(16,12): BCE0023: No appropriate version of 'UnityEngine.GUI.Box' for the argument list '(UnityEngine.Rect, int)' was found. Not sure why..... Haha..... Sorry for the CAPS. I was just VERY stressed out! :-\
It's because second argument can't be integer. This will sort it out.
GUI.Box(Rect(0,0,320,42),""+ pointscore);
or
GUI.Box(Rect(0,0,320,42),pointscore.ToString());
Of those two, use the second. The first does an implicit call to "ToString" anyway, but then adds another operation on top of that, so the second one is faster.
THAN$$anonymous$$ YOU BOTH VERY $$anonymous$$UCH!! )HappyTone)