using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class EconomyManager : Singleton { private TMP_Text goldText; // Reference to the UI text displaying the current gold amount private int currentGold = 0; // The player's current gold amount const string COIN_AMOUNT_TEXT = "Gold Amount Text"; // Name of the TextMeshPro component showing the gold count public GameObject victoryPanel; // Panel shown when the player collects the required amount of gold public TMP_Text victoryGoldCountText; // UI text that shows the gold count on the victory panel private const int requiredGoldCount = 100; // Gold amount required to trigger the victory panel private void Start() { // Find and assign the goldText component if not already set if (goldText == null) { goldText = GameObject.Find(COIN_AMOUNT_TEXT).GetComponent(); } UpdateGoldText(); // Initialize the gold amount display victoryPanel.SetActive(false); // Ensure the victory panel is hidden at the start } // Method to update the player's gold amount public void UpdateCurrentGold() { currentGold += 1; // Increment gold count UpdateGoldText(); // Refresh the displayed gold amount // Check if the player has collected enough gold to win if (currentGold >= requiredGoldCount) { ShowVictoryPanel(); // Display the victory panel } } // Method to reset the player's gold amount public void ResetGold() { currentGold = 0; // Reset gold count to 0 UpdateGoldText(); // Refresh the displayed gold amount victoryPanel.SetActive(false); // Hide the victory panel on reset } // Update the text displaying the current gold amount private void UpdateGoldText() { if (goldText != null) { goldText.text = currentGold.ToString("D3"); // Display the gold amount as a 3-digit number } } // Display the victory panel when the required gold amount is reached private void ShowVictoryPanel() { if (victoryGoldCountText != null) { victoryGoldCountText.text = currentGold.ToString("D3"); // Update victory panel's gold count } victoryPanel.SetActive(true); // Show the victory panel } }