Advertisement
Ipashilovo

Untitled

Jul 7th, 2021
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. public class CoinsView : MonoBehaviour
  2. {
  3.     [SerializeField] private CoinsCounter _coinsCounter;
  4.     [SerializeField] private TMP_Text _coins;
  5.  
  6.     private int _currentCoins = 0;
  7.  
  8.     private void Awake()
  9.     {
  10.         _currentCoins = PlayerPrefs.GetInt("Coins");
  11.  
  12.         if (_currentCoins >= 1000)
  13.             _coins.text = (_currentCoins / 1000).ToString() + "K";
  14.         else
  15.             _coins.text = _currentCoins.ToString();
  16.     }
  17.  
  18.     private void Update()
  19.     {
  20.         _currentCoins = PlayerPrefs.GetInt("Coins");
  21.  
  22.         if (_currentCoins < 1000)
  23.             _coins.text = (_currentCoins).ToString();
  24.         else
  25.             _coins.text = (_currentCoins / 1000).ToString() + "K";
  26.     }
  27.  
  28.     public void ChangeCoinsCount(int value)
  29.     {
  30.         _currentCoins -= value;
  31.  
  32.         if (_currentCoins < 1000)
  33.             _coins.text = (_currentCoins).ToString();
  34.         else
  35.             _coins.text = (_currentCoins / 1000).ToString() + "K";
  36.     }
  37.  
  38.     private void OnDestroy()
  39.     {
  40.         PlayerPrefs.SetInt("Coins", _currentCoins);
  41.         PlayerPrefs.Save();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement