Vesna Ivanovic
Vesna Ivanovic

Reputation: 27

Script in c# for local leaderboard

I need some help with scripting. I'm making a game in Unity for android.

The idea is to be a simple game without levels, without being demanding, but endearing. It's a single player game. One thing that left is to create leader-board so that players could be able to, after finishing the game, save the name, score, high-score and the results are ranked from highest to lowest.

Since i'm new to game programming, I need help.

I need to create a new script which would create leader board so that players could be able to, after finishing the game, save the name, score, high-score and the results are ranked from highest to lowest

Local, not for server.

Upvotes: 1

Views: 2394

Answers (2)

axwcode
axwcode

Reputation: 7824

Use PlayerPrefs

Code looks like this:

public class ScoreClass: MonoBehaviour 
{
    // Save.
    void SaveScore(int score) 
    {
        PlayerPrefs.SetInt("Player Score", score);
    }

    // Retrieve.
    void PrintScore()
    {
        print(PlayerPrefs.GetInt("Player Score"));
    }
}

You can also save floats, to know how check out the API.

Upvotes: 1

JRowan
JRowan

Reputation: 7104

You can use PlayerPrefs to make a leaderboard locally check this link PlayerPrefs

here is a link with an example using PlayerPrefs for local leaderboard example

Upvotes: 0

Related Questions