using UnityEngine; // This code is to demonstrate use of TheBest, a simple // single-entry "best score" or "best time" class. // // You can get the TheBest class here at these two pastes: // // For the highest score: https://pastebin.com/VmngEK05 // // For the lowest time: https://pastebin.com/A7GC76uQ // // To run this code you WILL NEED THE ABOVE! // // @kurtdekker // public class TheBestUsageExample : MonoBehaviour { void Start () { Report( "Begin!"); // comment this line out to see persistence from run to run ClearEverything(); AddSomeScores(); Report( "After adding scores!"); AddSomeTimes(); Report( "After adding times!"); } const string TimeFormatter = "0.00s"; void Report( string title) { string s = title + ": "; s += "HaveBestScore:" + TheBest.HaveBestScore; if (TheBest.HaveBestScore) { s += " Best Score is:" + TheBest.BestScore; } s = s + "\n"; s += "HaveBestTime:" + TheBest.HaveBestTime; if (TheBest.HaveBestTime) { s += " Best Time is:" + TheBest.BestTime.ToString( TimeFormatter); } Debug.Log( s); } void ClearEverything() { Debug.Log( "Clearing everything!"); TheBest.ClearBestScore(); TheBest.ClearBestTime(); Report( "After clear!"); } void AddSomeScores() { TheBest.RecordScoreIfHigher( 10); Debug.Log( "The best score: " + TheBest.BestScore); TheBest.RecordScoreIfHigher( 30); Debug.Log( "The best score: " + TheBest.BestScore); TheBest.RecordScoreIfHigher( 20); Debug.Log( "The best score: " + TheBest.BestScore); } void AddSomeTimes() { TheBest.RecordTimeIfLower( 12.5f); Debug.Log( "The best time: " + TheBest.BestTime.ToString( TimeFormatter)); TheBest.RecordTimeIfLower( 22.5f); Debug.Log( "The best time: " + TheBest.BestTime.ToString( TimeFormatter)); TheBest.RecordTimeIfLower( 2.5f); Debug.Log( "The best time: " + TheBest.BestTime.ToString( TimeFormatter)); } }