Hello guys,
I have created a 2D game, regardless I'm not a developer, but I have followed a tutorial and so far i'm doing pretty well. My game is almost done let's say, even inside the tutorial the language was C# and again i'm learning the basic things when it comes to coding.
However, what concerns me right now is how to implement a leader board inside my game? Because you know, the game would be really useless without a leader board.
Anyone might help me by sharing some techniques, maybe some tutorial or anything?
Thank you ,
Salim
Replies
serializing & storing the data - that is actually pretty easy with the .net xml stuff, but you'll need to read quite a few docs for this. In the end you want to define a simple data structure which contains your leaderboard entry and throw that into a list/array.
pseudo c#:
[System.Serializable]
Class ScoreItem
{
public string name;
public int score;
}
list<ScoreItem>{
{
name: foo;
score: 123;
}
1:
{
name: bar;
score: 99;
}
}
once you can read/write this data structure youll have to load it on startup, update & store the list after each level end or whatever.
yeah and you'll have to create the ui code for this, to actually show the data list. In my mind the list entry is a prefab/part_of_a_screen which you just grab as a 'definition', loop over alle the items in the list, and instantiate
a list entry item - which you place into a scrollview. I think there are some layout components in unity which do all the placement..
for item in scores:
entry = create_entry(item.name, item.score);
scrollview.append(entry);
In programming knowing the right terms to search for really helps... so this should get you started.
But there you can only store one key and value. But you can serialize values "manually" to a string and store multiple values (strings, ints) in one value.
I did this recently to store multiple string values as a list in the player preferences.
The script below is for storing and removing favorites. It stores multiple strings that belong to one entry.