Advertisement
moinularif

SaveScore

May 14th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SaveScore : MonoBehaviour {
  5.  
  6.     void Start()
  7.     {
  8.  
  9.     }
  10.  
  11.     public void AddScore(string name, int score, int id)
  12.     {
  13.         int newScore;
  14.         string newName;
  15.         int newid;
  16.         int oldScore;
  17.         string oldName;
  18.         int oldid;
  19.         newScore = score;
  20.         newName = name;
  21.         newid = id;
  22.         for (int i = 0; i < 10; i++)
  23.         {
  24.             if (PlayerPrefs.HasKey(i + "HScore"))
  25.             {
  26.                 if (PlayerPrefs.GetInt(i + "HScore") < newScore)
  27.                 {
  28.  
  29.                     oldScore = PlayerPrefs.GetInt(i + "HScore");
  30.                     oldName = PlayerPrefs.GetString(i + "HScoreName");
  31.                     oldid = PlayerPrefs.GetInt(i + "HScoreID");
  32.                     PlayerPrefs.SetInt(i + "HScore", newScore);
  33.                     PlayerPrefs.SetString(i + "HScoreName", newName);
  34.                     PlayerPrefs.SetInt(i + "HScoreID", newid);
  35.  
  36.                     newScore = oldScore;
  37.                     newName = oldName;
  38.                     newid = oldid;
  39.                 }
  40.             }
  41.             else
  42.             {
  43.                 PlayerPrefs.SetInt(i + "HScore", newScore);
  44.                 PlayerPrefs.SetString(i + "HScoreName", newName);
  45.                 PlayerPrefs.SetInt(i + "HScoreID", newid);
  46.                 newScore = 0;
  47.                 newName = "";
  48.                 newid = 0;
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement