Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class SaveScore : MonoBehaviour {
- void Start()
- {
- }
- public void AddScore(string name, int score, int id)
- {
- int newScore;
- string newName;
- int newid;
- int oldScore;
- string oldName;
- int oldid;
- newScore = score;
- newName = name;
- newid = id;
- for (int i = 0; i < 10; i++)
- {
- if (PlayerPrefs.HasKey(i + "HScore"))
- {
- if (PlayerPrefs.GetInt(i + "HScore") < newScore)
- {
- oldScore = PlayerPrefs.GetInt(i + "HScore");
- oldName = PlayerPrefs.GetString(i + "HScoreName");
- oldid = PlayerPrefs.GetInt(i + "HScoreID");
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetInt(i + "HScoreID", newid);
- newScore = oldScore;
- newName = oldName;
- newid = oldid;
- }
- }
- else
- {
- PlayerPrefs.SetInt(i + "HScore", newScore);
- PlayerPrefs.SetString(i + "HScoreName", newName);
- PlayerPrefs.SetInt(i + "HScoreID", newid);
- newScore = 0;
- newName = "";
- newid = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement