Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- // by @kurtdekker - ultra simple best time backing store
- public static partial class TheBest
- {
- // for times: lower is better
- private static string s_LowestTime = "LowestTime";
- public static bool HaveBestTime
- {
- get
- {
- return PlayerPrefs.HasKey(s_LowestTime);
- }
- }
- public static float BestTime
- {
- get
- {
- return PlayerPrefs.GetFloat(s_LowestTime, 0);
- }
- private set // make this public if you trust yourself
- {
- PlayerPrefs.SetFloat(s_LowestTime, value);
- }
- }
- public static bool RecordTimeIfLower(float time)
- {
- if (!HaveBestTime || (time < BestTime))
- {
- BestTime = time;
- return true;
- }
- return false;
- }
- public static void ClearBestTime()
- {
- if (HaveBestTime)
- {
- PlayerPrefs.DeleteKey(s_LowestTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement