I have a game that only saves one score and displays it on the main menu. Here is the code
using UnityEngine;
using System.Collections;
public class KeepingScore : MonoBehaviour {
private GUISkin skin;
public static int Score = 0;
double timer = 0.0;
void OnDestroy()
{
// save highscore
if (Score > PlayerPrefs.GetInt ("Score")) {
PlayerPrefs.SetInt ("Score", Score);
}
}
it is attached to the main player so when the player dies it saves the score and displays it on the main menu in a 3d text mesh object. Here is the code.
using UnityEngine;
public class MenuScript : MonoBehaviour
{
private GUISkin skin;
public TextMesh bScore;
void Awake(){
bScore.text = "Hi-Score: " + PlayerPrefs.GetInt("Score");
}
**I was wondering how do I save multiple scores in a scoreboard like
Name - 99999
Name - 9999
Name 99
Maybe on a different leaderboard scene something.
Thank you. Example scripts and instructions would be much appreciated.**
What you could do is add a new GUI Label for each score. Create an array of high scores, and an array of names, and then fill it in each time a score is saved.
Completely untested, but that should, if I’ve written it right, give you a list of scores offset by 40 pixels each time with the next name and score in the row.
Hope this helps a little. If the code doesn’t work, sorry- my C# is a little rusty.