gandalfbialy

Untitled

Jul 19th, 2025
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.61 KB | None | 0 0
  1. using UnityEngine;
  2. using TMPro;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.UI;
  5.  
  6. public class MenuManager : MonoBehaviour
  7. {
  8.     public TextMeshProUGUI highscoreValue;
  9.     public TextMeshProUGUI coinsValue;
  10.     public TextMeshProUGUI soundButtonText;
  11.  
  12.     private int highscore = 0;
  13.     private int coins = 0;
  14.  
  15.     public GameObject mainMenuPanel;
  16.     public GameObject upgradesStorePanel;
  17.  
  18.     public Text magnetLevelText;
  19.     public Text magnetButtonText;
  20.  
  21.     public Text immortalityLevelText;
  22.     public Text immortalityButtonText;
  23.  
  24.     public Powerup magnet;
  25.     public Powerup immortality;
  26.  
  27.     public void OpenUpgradeStore()
  28.     {
  29.         mainMenuPanel.SetActive(false);
  30.         upgradesStorePanel.SetActive(true);
  31.     }
  32.  
  33.     public void CloseUpgradeStore()
  34.     {
  35.         mainMenuPanel.SetActive(true);
  36.         upgradesStorePanel.SetActive(false);
  37.     }
  38.  
  39.     void Start()
  40.     {
  41.         if (PlayerPrefs.HasKey("HighscoreValue"))
  42.         {
  43.             highscore = PlayerPrefs.GetInt("HighscoreValue");
  44.         }
  45.  
  46.         if (PlayerPrefs.HasKey("Coins"))
  47.         {
  48.             coins = PlayerPrefs.GetInt("Coins");
  49.         }
  50.  
  51.         UpdateUI();
  52.     }
  53.  
  54.     public void UpdateUI()
  55.     {
  56.         highscoreValue.text = highscore.ToString();
  57.         coinsValue.text = coins.ToString();
  58.  
  59.         if (SoundManager.instance.GetMuted())
  60.         {
  61.             soundButtonText.text = "Music ON";
  62.         }
  63.         else
  64.         {
  65.             soundButtonText.text = "Music OFF";
  66.         }
  67.  
  68.         immortalityLevelText.text = immortality.ToString();
  69.         immortalityButtonText.text = immortality.UpgradeCostString();
  70.         magnetLevelText.text = magnet.ToString();
  71.         magnetButtonText.text = magnet.UpgradeCostString();
  72.     }
  73.  
  74.     public void UpgradeImmortalityButton()
  75.     {
  76.         UpgradePowerup(immortality);
  77.     }
  78.  
  79.     public void UpgradeMagnetButton()
  80.     {
  81.         UpgradePowerup(magnet);
  82.     }
  83.     private void UpgradePowerup(Powerup powerup)
  84.     {
  85.         if (coins >= powerup.GetNextUpgradeCost() && !powerup.IsMaxedOut())
  86.         {
  87.             ReduceCoinsAmount(powerup.GetNextUpgradeCost());
  88.             powerup.Upgrade();
  89.             UpdateUI();
  90.         }
  91.     }
  92.     private void ReduceCoinsAmount(int amount)
  93.     {
  94.         coins -= amount;
  95.         PlayerPrefs.SetInt("Coins", coins);
  96.     }
  97.  
  98.     public void PlayButtonClicked()
  99.     {
  100.         SceneManager.LoadScene("Game");
  101.     }
  102.     public void SoundButtonClicked()
  103.     {
  104.         SoundManager.instance.ToggleMuted();
  105.         UpdateUI();
  106.     }
  107.  
  108.  
  109.     void Update()
  110.     {
  111.        
  112.     }
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment