Advertisement
Guest User

Unity high score and low time demo

a guest
Mar 3rd, 2021
1,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. // This code is to demonstrate use of TheBest, a simple
  4. // single-entry "best score" or "best time" class.
  5. //
  6. // You can get the TheBest class here at these two pastes:
  7. //
  8. //  For the highest score: https://pastebin.com/VmngEK05
  9. //
  10. //  For the lowest time: https://pastebin.com/A7GC76uQ
  11. //
  12. // To run this code you WILL NEED THE ABOVE!
  13. //
  14. // @kurtdekker
  15. //
  16.  
  17. public class TheBestUsageExample : MonoBehaviour
  18. {
  19.     void Start ()
  20.     {
  21.         Report( "Begin!");
  22.  
  23.         // comment this line out to see persistence from run to run
  24.         ClearEverything();
  25.  
  26.         AddSomeScores();
  27.  
  28.         Report( "After adding scores!");
  29.  
  30.         AddSomeTimes();
  31.  
  32.         Report( "After adding times!");
  33.     }
  34.  
  35.     const string TimeFormatter = "0.00s";
  36.  
  37.     void Report( string title)
  38.     {
  39.         string s = title + ": ";
  40.  
  41.         s += "HaveBestScore:" + TheBest.HaveBestScore;
  42.         if (TheBest.HaveBestScore)
  43.         {
  44.             s += "  Best Score is:" + TheBest.BestScore;
  45.         }
  46.         s = s + "\n";
  47.  
  48.         s += "HaveBestTime:" + TheBest.HaveBestTime;
  49.         if (TheBest.HaveBestTime)
  50.         {
  51.             s += "  Best Time is:" + TheBest.BestTime.ToString( TimeFormatter);
  52.         }
  53.         Debug.Log( s);
  54.     }
  55.  
  56.     void ClearEverything()
  57.     {
  58.         Debug.Log( "Clearing everything!");
  59.  
  60.         TheBest.ClearBestScore();
  61.         TheBest.ClearBestTime();
  62.  
  63.         Report( "After clear!");
  64.     }
  65.  
  66.     void AddSomeScores()
  67.     {
  68.         TheBest.RecordScoreIfHigher( 10);
  69.  
  70.         Debug.Log( "The best score: " + TheBest.BestScore);
  71.  
  72.         TheBest.RecordScoreIfHigher( 30);
  73.  
  74.         Debug.Log( "The best score: " + TheBest.BestScore);
  75.  
  76.         TheBest.RecordScoreIfHigher( 20);
  77.  
  78.         Debug.Log( "The best score: " + TheBest.BestScore);
  79.     }
  80.  
  81.     void AddSomeTimes()
  82.     {
  83.         TheBest.RecordTimeIfLower( 12.5f);
  84.  
  85.         Debug.Log( "The best time: " + TheBest.BestTime.ToString( TimeFormatter));
  86.  
  87.         TheBest.RecordTimeIfLower( 22.5f);
  88.  
  89.         Debug.Log( "The best time: " + TheBest.BestTime.ToString( TimeFormatter));
  90.  
  91.         TheBest.RecordTimeIfLower( 2.5f);
  92.  
  93.         Debug.Log( "The best time: " + TheBest.BestTime.ToString( TimeFormatter));
  94.     }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement