Basic Game Score Question.

Hi there!

I'm creating a game where the player collects items and each time the player collides with an item the score increases using these simple scripts.

var theScore : int =0;

function Update () {

guiText.text = "Golden Orbs: "+theScore;

}

...

and the script on the player:

function OnControllerColliderHit(theCollision : ControllerColliderHit) {

    if(theCollision.gameObject.name == "orb") {
        Destroy(theCollision.gameObject);
        gameObject.Find("score").GetComponent(textScript).theScore+=1;
    }
}

at the end of the level time the level moves to a menu screen. I'd like to display this score in a guitext, what code would help me display this score bearing in mind its in a new level.

Thanks!

Here is what I do :

Make a new, empty game object, something like ScoreKeeper is what I use. Then, put a static variable on there like currentScore. Then, whenever you update the score as normal, you update the ScoreKeeper object, currentScore variable. Put a "dontdestroyonload" within the scorekeeper and you can keep it between levels. At the start of the next gameplay level, you can just zero it out and start over if you want to, or keep adding more score on to what you already had.