Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- // by @kurtdekker - ultra simple best score backing store
- public static partial class TheBest
- {
- // for scores: higher is better
- private static string s_HighScore = "HighScore";
- public static bool HaveBestScore
- {
- get
- {
- return PlayerPrefs.HasKey(s_HighScore);
- }
- }
- public static float BestScore
- {
- get
- {
- return PlayerPrefs.GetFloat(s_HighScore, 0);
- }
- private set // make this public if you trust yourself
- {
- PlayerPrefs.SetFloat(s_HighScore, value);
- }
- }
- public static bool RecordScoreIfHigher(int score)
- {
- if (!HaveBestScore || (score > BestScore))
- {
- BestScore = score;
- return true;
- }
- return false;
- }
- public static void ClearBestScore()
- {
- if (HaveBestScore)
- {
- PlayerPrefs.DeleteKey(s_HighScore);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement