- Home /
Scoreboard Setup
Hi, I have looked all over the web and I just can't get my scoreboard script to work. I am basically trying to make it so when someone presses 'space' a GUI Text on screen increases by 1 (e.g. Score: 0, Score: 1) I have attached it to the GUI Text. It seems fairly basic compared to other scoreboard scripts but I just can't get the GUI Text to change. When played the variable "score" increases by 1, however, the GUI Text doesn't change. Please have a look!
I used Javascript, here it is:
#pragma strict
private var score : int;
var scoreboard : GUIText;
function Start () {
UpdateScore ();
}
function Update () {
if(Input.GetKeyDown(KeyCode.Space)){
score += 1;
}
}
function UpdateScore () {
scoreboard.text = "Score: " + score;
}
Answer by Sospitas · Jul 18, 2014 at 10:52 AM
Your UpdateScore function is only called within Start.
You will want to call it within Update for it to continuously Update the value of the GUIText variable
Answer by nath23725652 · Jul 18, 2014 at 11:42 AM
Thanks you so much! You have no idea how long I spent researching stuff just for a simple noobie error. I'm fairly new so thank you, but I'm starting to understand javascript. Sorry I couldn't thumbs up you or something.
Your answer
![](https://koobas.hobune.stream/wayback/20220613154405im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Score display in specific format 1 Answer
scoreboard for multiplayer game 0 Answers
Score display error 1 Answer
Creating a scoreboard 1 Answer