- Home /
How to add and keep score in every level?
Hello all, I'm a PhD student and I'm doing a simple game of collecting coins for my research. The question might be silly but I'm not a programmer. I'm trying to keep and add score in every level, but when the new scene is loaded the score starts again from the zero. My code so far is:
static var score=0; var guiScore :
GUIText;
function start () {
guiScore.text = "Coins: "+score;
}
function OnTriggerEnter (other :Collider )
{
Debug.Log ("OnTriggerEnter () was called");
if (other.tag == "Coin") {
Debug.Log ("Other object is coin");
score ++;
Debug.Log
("Score is now " + score);
Destroy (other.gameObject);
guiScore.text = "Coins : " +score;
Timer.onpause = true;
Application.LoadLevel("Menu2");
} }
I would really appreciate any help. Thanks in advance.
Format your code! Highlight text and click 101010 button
Answer by meat5000 · Nov 20, 2013 at 04:36 PM
Basically this function on the gameobject your score scripts are on should make the object persist between levels.
Alternatively save off the value to playerprefs.
Your answer
Follow this Question
Related Questions
Referencing Scripts properly and still not working? Help! 1 Answer
How to add a score 1 Answer
script woe adding score 1 Answer
Add to score every second 3 Answers
My score script doesn't seem to work properly, score is not added properly 0 Answers