Question about making a scoreboard as a singleton

You might be tackling this later in the course, but if I wanted to make a scoreboard could I for instance to that with a singleton called for instance ScoreKeeper?

I’m thinking ScoreKeeper would keep a sorted 2D array of names and scores.
The Start Menu scene would ask for this data and present it in a nice list.
The Game Over scene would check with ScoreKeeper if the score was high enough to get on the list and if so, Game Over would ask for name/initials and send those back to ScoreKeeper.

Would that work?

Hi Frank,

Yes, that’s possible.

However, if all you want to do is keeping track of names and scores, I would suggest to write a normal C# class which does not inherit from MonoBehaviour. Make it an actual singleton. You will be able to access it in other instances without having to look for an object in your scene. As long as your game runs, this object will persist.

Regarding the singleton implementation, I usually use the first example on this website. If you want to access an object of the class, all you have to do is to call: Singleton variableName = Singleton.Instance.

Replace the name Singleton with your preferred class name.

I hope this helped. :slight_smile:

1 Like

Thanks, Nina!

I’ll check it out and see if I can understand it and make it work.

If you get stuck, share what you have, and I’ll try to help you.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms