Global scoring system

Hi,

I’m pretty new to using unity but I was trying to implement a scoring system and wanted to make sure I use a good architecture when setting it up. Basically when an object hits a certain type of object the system should increment a score. If this was a one level thing I would be fine but I want this to persist across the entire game and all of the levels, not just one. I’ve considered using a singleton but I’m not sure where I would put this object. Is there an easy way to have a global object that persists through all scenes? Or is there a better way to setup the scoring system? Thanks in advance

If you want to save data between different sessions you should look into the PlayerPrefs. To simply keep data in a script ‘alive’ between scenes, use DontDestroyOnLoad on the script.

If you indeed don’t want to ‘save’ the data but just keep it around I’d have an empty GameObject on the very first scene you load up. Call the GameObject “Stats” or something else that seems practical and attach a script to it with DontDestroyOnLoad.

You do not need to create a object for that. You can just use static variables.

Simply create a script, name it “GameStatus”. Declare your global variable in it:

static var score:int;

Access the variable in any script by:

GameStatus.score+=100;