1

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.

apxcode
  • 7,696
  • 7
  • 30
  • 41

2 Answers2

1

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.

apxcode
  • 7,696
  • 7
  • 30
  • 41
0

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

JRowan
  • 6,824
  • 8
  • 40
  • 59
  • public class Score : MonoBehaviour { static int score = 0; static int highScore = 0; static public void AddPoint() { score++; if (score > highScore) { highScore = score; } } void Start () { highScore = PlayerPrefs.GetInt ("your high score", 0); } void OnDestroy () { PlayerPrefs.SetInt ("your high score", highScore); } void Update () { guiText.text = "your score: " + score + "\nyour high score: " + highScore;} } – Vesna Ivanovic Oct 16 '14 at 06:41
  • I tried to connect this script with my script but i have to import score and name mannualy... – Vesna Ivanovic Oct 16 '14 at 06:47