You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
using TMPro; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class Store : MonoBehaviour |
|
{ |
|
[SerializeField] |
|
private GameManager gameManager; |
|
[SerializeField] |
|
private TextMeshProUGUI StoreCountText; |
|
[SerializeField] |
|
private Button BuyButton; |
|
[SerializeField] |
|
private Slider StoreSlider; |
|
|
|
private int StoreCount = 0; |
|
private decimal BaseStorePrice = 1.00M; |
|
private decimal StoreProfit = 0.50M; |
|
|
|
private float StoreReset = 4.0f; |
|
private float StoreTime = 0.0f; |
|
bool StoreOpen = false; |
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created |
|
void Start() |
|
{ |
|
StoreCountText.text = StoreCount.ToString(); |
|
|
|
} |
|
|
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
if(StoreOpen) |
|
{ |
|
StoreTime += Time.deltaTime; |
|
if (StoreTime >= StoreReset) |
|
{ |
|
StoreOpen = false; |
|
StoreTime = 0.0f; |
|
gameManager.AddToBalance(StoreProfit * StoreCount); |
|
} |
|
|
|
} |
|
StoreSlider.value = StoreTime / StoreReset; |
|
if(gameManager.CanAfford(BaseStorePrice)) |
|
{ |
|
BuyButton.interactable = true; |
|
} |
|
} |
|
|
|
public void Buy() |
|
{ |
|
gameManager.SubtractFromBalance(BaseStorePrice); |
|
StoreCount++; |
|
StoreCountText.text = StoreCount.ToString(); |
|
if(!gameManager.CanAfford(BaseStorePrice)) |
|
{ |
|
BuyButton.interactable = false; |
|
} |
|
} |
|
|
|
public void OpenStore() |
|
{ |
|
StoreOpen = true; |
|
|
|
} |
|
|
|
}
|
|
|