chip-game/Assets/Scripts/CoinCounter.cs

55 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class CoinCounter : MonoBehaviour
{
public TextMeshProUGUI tmp;
public TextMeshProUGUI revengeSign;
public GameObject revengeSignGo;
void OnEnable()
{
SetRevengePriceVisibility(false);
UpdateCoins(PlayerPrefs.GetInt("CoinsCount", 0));
SingleWallet.onCoinAdded.AddListener(UpdateCoins);
SingleWallet.onCoinRemoved.AddListener(UpdateCoins);
SettingsManager.OnSettingsChanged.AddListener(UpdateCoins);
}
private void OnDisable()
{
SingleWallet.onCoinAdded.RemoveListener(UpdateCoins);
SingleWallet.onCoinRemoved.AddListener(UpdateCoins);
}
private void UpdateCoins() => UpdateCoins(SingleWallet.Balance);
public void UpdateCoins(int newCount)
{
string valutaName = PlayerPrefs.GetString("ValutaName", "руб.");
tmp.text = $"Баланс:<br>{newCount} {valutaName}";
}
public void SetRevengePriceVisibility(bool visibility)
{
revengeSignGo.SetActive(visibility);
int priceRevenge = PlayerPrefs.GetInt("PriceRevenge", 10);
int pricePve = PlayerPrefs.GetInt("PricePVE", 10);
string valutaName = PlayerPrefs.GetString("ValutaName", "руб.");
if(priceRevenge < pricePve)
{
revengeSign.text = $"Цена игры: <br><s>{pricePve} {valutaName}</s><br><color=green>Повторная игра:<br><u>{priceRevenge} {valutaName}</u></color>";
}
else
{
revengeSign.text = $"Повторная игра:<br><u>{priceRevenge} {valutaName}</u>";
}
}
}