EndGameMenu.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using TMPro;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. public class EndGameMenu : MonoBehaviour
  5. {
  6. private SaveManager saveManager;
  7. GameData gameData;
  8. public TMP_Text textToDisplay;
  9. public TMP_Text score;
  10. // Start is called once before the first execution of Update after the MonoBehaviour is created
  11. void Start()
  12. {
  13. saveManager = GameObject.Find("SaveManager").GetComponent<SaveManager>();
  14. gameData = saveManager.LoadGame();
  15. if(gameData.playerScore >= 10)
  16. {
  17. textToDisplay.text = "You won! Well played!";
  18. score.text = "You collected every orbs (10)";
  19. }
  20. else
  21. {
  22. textToDisplay.text = "You lost! Skill issue.";
  23. score.text = "You collected only " + gameData.playerScore.ToString() + "/10 Orbs";
  24. }
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. }
  30. public void NewGame()
  31. {
  32. GameData gameData = new();
  33. System.Random rnd = new();
  34. gameData.seed = rnd.Next();
  35. saveManager.SaveGame(gameData);
  36. SceneManager.LoadScene("Game");
  37. }
  38. public void MainMenu()
  39. {
  40. GameData gameData= new();
  41. saveManager.SaveGame(gameData);
  42. SceneManager.LoadScene("Menu");
  43. }
  44. public void Quit()
  45. {
  46. Application.Quit();
  47. }
  48. }