using System; using TMPro; using UnityEngine; using UnityEngine.UI; public class Store : MonoBehaviour { [SerializeField] private GameManager gameManager; [Header("Store Settings")] [SerializeField] [Tooltip("Base price of store")] private float BaseStorePrice = 1.00f; [SerializeField] [Tooltip("Amount that the Price multiplies for each store purchase")] private float PriceMultiplier = 1.10f; [SerializeField] [Tooltip("Profit made by store per reset")] private float StoreProfit = 0.50f; [SerializeField] [Tooltip("Time in seconds until store makes a profit")] private float StoreReset = 4.0f; [SerializeField] [Tooltip("Turns on/off the store manager")] private bool ManagerOpen = false; [Header("Store UI")] [SerializeField] private TextMeshProUGUI StoreCountText; [SerializeField] private Button BuyButton; [SerializeField] private Slider StoreSlider; private int StoreCount = 0; private float StoreTime = 0.0f; private float NextStorePrice = 0.0f; private TextMeshProUGUI BuyButtonText; bool StoreOpen = false; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { NextStorePrice = BaseStorePrice; BuyButtonText = BuyButton.GetComponentInChildren(); BuyButtonText.text = String.Format("Buy: {0:C2}", NextStorePrice); StoreCountText.text = StoreCount.ToString(); } // Update is called once per frame void Update() { if(StoreOpen) { StoreTime += Time.deltaTime; if (StoreTime >= StoreReset) { if (!ManagerOpen) { StoreOpen = false; } StoreTime = 0.0f; gameManager.AddToBalance(StoreProfit * StoreCount); } } StoreSlider.value = StoreTime / StoreReset; if(gameManager.CanAfford(NextStorePrice)) { BuyButton.interactable = true; } } public void Buy() { StoreCount++; StoreCountText.text = StoreCount.ToString(); NextStorePrice = BaseStorePrice * Mathf.Pow(PriceMultiplier, StoreCount); BuyButtonText.text = String.Format("Buy: {0:C2}", NextStorePrice); gameManager.SubtractFromBalance(NextStorePrice); if (!gameManager.CanAfford(NextStorePrice)) { BuyButton.interactable = false; } } public void OpenStore() { StoreOpen = true; } }