Advertisement
dronkowitz

ScoreSystem.cs

Jun 28th, 2021 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.35 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using UnityEngine.SceneManagement;
  7.  
  8. public class ScoreSystem : MonoBehaviour
  9. {
  10.     public GameObject Player;
  11.     public GameObject NormalHUD;
  12.     public GameObject scoreSystem;
  13.     public TMP_Text SpeedCharacterScore;
  14.     public TMP_Text FlyingCharacterScore;
  15.     public TMP_Text PowerCharacterScore;
  16.     public TMP_Text TimeScore;
  17.     public TMP_Text RingCountScore;
  18.     public TMP_Text TimeBonusScore; // The faster in time that the player goes the better the grade will be
  19.     public TMP_Text FinalScore;
  20.     public Image FinalGrade; //This displays the actual grade based on the time you have beaten the level
  21.     public static int prospectiveScore;
  22.     public static float finalScore;
  23.     public static int SpeedScore;
  24.     public static int FlyScore;
  25.     public static int PowerScore;
  26.     public Sprite gradeA, gradeB, gradeC, gradeD, gradeE;
  27.     // Start is called before the first frame update
  28.     void Start()
  29.     {
  30.         prospectiveScore = 0;
  31.         finalScore = 0;
  32.  
  33.     }
  34.  
  35.     // Update is called once per frame
  36.     void Update()
  37.     {
  38.  
  39.     }
  40.     public void StartEndLevelSequence()
  41.     {
  42.         NormalHUD.gameObject.SetActive(false);
  43.         scoreSystem.SetActive(true);
  44.         FindObjectOfType<UltimatePlayerMovement>().enabled = false;
  45.         StartCoroutine(EndLevelSequence());
  46.     }
  47.     public IEnumerator EndLevelSequence()
  48.     {
  49.         //Display Team Score Per Level
  50.         int SpeedCharScore = GameInstance.speedScore;
  51.         int FlyingCharScore = GameInstance.flyScore;
  52.         int PowerCharScore = GameInstance.powerScore;
  53.  
  54.         //Time Calculation
  55.         float TimeScoreInt = HUD.timer;
  56.         float SecondScoreint = 0;
  57.         float MinutesScoreint = 0;
  58.         float MilliSecondScoreint = 0;
  59.         while (TimeScoreInt > 1)
  60.         {
  61.             TimeScoreInt -= 1;
  62.             SecondScoreint += 1;
  63.             if (SecondScoreint == 60)
  64.             {
  65.                 SecondScoreint -= 60;
  66.                 MinutesScoreint += 1;
  67.             }
  68.         }
  69.         MilliSecondScoreint = Mathf.RoundToInt(TimeScoreInt * 100);
  70.  
  71.         //Time Score Calculation
  72.         int RingCountint = GameInstance.currentRings;
  73.         float TimeBonusint = GameInstance.bonusScore;
  74.         float BonusTimeint = HUD.timer; // The faster in time that the player goes the better the grade will be
  75.         float TotalTimeint = HUD.timer;
  76.         float FinalScoreint = HUD.timer;
  77.  
  78.         if (TotalTimeint >= 625)
  79.         {
  80.             BonusTimeint = 0;
  81.         }
  82.  
  83.         else
  84.         {
  85.             float secondCount = 625 - TotalTimeint;
  86.             BonusTimeint = secondCount * 80;
  87.         }
  88.  
  89.         BonusTimeint = Mathf.RoundToInt(BonusTimeint);
  90.        
  91.         //Displays Main Team Score
  92.         //Display Time Score and Ring Count Scores with Time Bonus Score
  93.         SpeedCharacterScore.text = GameInstance.speedScore.ToString();
  94.         FlyingCharacterScore.text = GameInstance.flyScore.ToString();
  95.         PowerCharacterScore.text = GameInstance.powerScore.ToString();
  96.         TimeScore.text = MinutesScoreint.ToString("00") + ":" + SecondScoreint.ToString("00") + ":" + MilliSecondScoreint.ToString("00");
  97.         RingCountScore.text = GameInstance.currentRings.ToString();
  98.         TimeBonusScore.text = BonusTimeint.ToString();
  99.  
  100.  
  101.  
  102.  
  103.         //1 Second = 100
  104.  
  105.         //Display List of Score System
  106.         //1. Lists each character's score
  107.         //2.Adds powerups to character scores
  108.         //3.Displays Time, Rings, TimeBonus
  109.         //4.Adds Rings to TimeBonus, subtracts Time from TimeBonus
  110.         //5.Add character scores, TimeBonus into FinalScore
  111.         //6.Display FinalScore
  112.         //7.Display letter grade
  113.  
  114.         // Every minute subtracts 1,000 points from a starting timebonusscore of 10,000
  115.  
  116.        
  117.         finalScore = 0;
  118.         finalScore = SpeedCharScore + FlyingCharScore + PowerCharScore;
  119.         finalScore += 10 * GameInstance.currentRings;
  120.         finalScore += BonusTimeint;
  121.  
  122.         FinalScore.text = finalScore.ToString();
  123.  
  124.         //Change Grade Based On Score Requirement Chart
  125.        
  126.         Ranking ranks = Resources.Load<Ranking>("Level Rankings/" + SceneManager.GetActiveScene().name);
  127.         int[] scores = new int[0];
  128.  
  129.  
  130.  
  131.        
  132.  
  133.         switch (TeamSetup.pc.CurrentTeam.SpeedCharacter.gameObject.name)
  134.         {
  135.  
  136.             //Displays who is the leader of the selected team
  137.             case "Sonic The Hedgehog":
  138.                 scores = ranks.teamSonic;
  139.                 break;
  140.             case "Shadow The Hedgehog":
  141.                 scores = ranks.teamDark;
  142.                 break;
  143.             case "Amy Rose":
  144.                 scores = ranks.teamRose;
  145.                 break;
  146.             case "Espio the Chameleon":
  147.                 scores = ranks.teamChaotix;
  148.                 break;
  149.         }
  150.  
  151.        
  152.         if (finalScore > scores[0])
  153.             FinalGrade.sprite = gradeA;
  154.  
  155.         else if (finalScore > scores[1])
  156.             FinalGrade.sprite = gradeB;
  157.  
  158.         else if (finalScore > scores[2])
  159.             FinalGrade.sprite = gradeC;
  160.  
  161.         else if (finalScore > scores[3])
  162.             FinalGrade.sprite = gradeD;
  163.  
  164.         else
  165.             FinalGrade.sprite = gradeE;
  166.  
  167.        
  168.  
  169.  
  170.         yield return null;
  171.     }
  172. }
  173.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement