Score System help

Ok so I have a score system set up and i was wondering what do I put in the “Score” area so that the text displayed the scores that change

here is the script:

guiText.text = "Score:";
guiText.pixelOffset = Vector2 (10, 10);

Well, that script snippet isn’t very useful, but that’s ok.

Assuming you have a ‘score’ variable (a float or int or whatever that stores what the current score is), you can use

guiText.text = "Score: " + score.ToString();

to set the text. Put this in Update, otherwise it won’t change as your score gets updated.

Otherwise, if you think it’s too inefficient resetting the guiText.text every frame when your score doesn’t update that often, you could inline it whenever you increment the score!

function AddScore(scoreToAdd : int)
{
    score += scoreToAdd;
    guiText.text = "Score: " + score.ToString();

}

Now, if you were using C# you could get even smarter, and set it up so that it’s impossible to set the score without updating the GUIText!

private int _myScore;
private GUIText _myText;
public int score
{
    get{return _myScore;}
    set{
        if(_myText == null)
        {
            _myText = guiText;
        }
        _myScore = value;
        _myText.text = guiText.text = "Score: " + myScore.ToString();
    }
}

The fact that you can’t do stuff like this in JavaScript is one reason I don’t use that language…