Scoring system help......

Hi I am currently developing a 2D game. Im not sure how to make the scoring system so that it remembers the highest score…currently i have this

using UnityEngine;

public class Generate : MonoBehaviour
{
public GameObject rocks;
int score = 0;

// Use this for initialization
void Start()
{
InvokeRepeating(“CreateObstacle”, 1f, 1.5f);
}

// Update is called once per frame
void OnGUI ()
{
GUI.color = Color.black;
GUILayout.Label(" Score: " + score.ToString());
}

void CreateObstacle()
{
Instantiate(rocks);
score++;
}
}

When you’re game ends, just save the score in some persistent manner. The easiest way is to use Player Prefs, but you can and should look into different serialization/saving techniques (xml, for instance).

As an aside, I would create a string to store your score. Every time your score changes, use ToString to store the new score string. Right now you are creating a new string every GUI update, which will lead to some unnecessary garbage generation, since your score only changes every 1.5 second.

Also, this should be in the scripting sub forum.

You could use our Core GameKit plugin (link in signature) which has “high score” mode for World Variables built in. It can keep track of all your other stats and also has built-in pooling, combat, spawners and requires no coding. Has scripts to display the score as well with NGUI or the new Unity 4.6 UI.

Hope that helps!

Thanks i’ll be sure to check it!