SHARE
TWEET

ItemInfo

AppingCS Jun 1st, 2020 896 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. //Script by Andriy Skyba
  4. namespace FeelkepStudio
  5. {
  6.     public class ItemInfo : MonoBehaviour
  7.     {
  8.         public string ItemName;
  9.         public int ItemCount;
  10.         public int ItemCost;
  11.         [SerializeField] Text ImageText;
  12.         public Text ButtonText;
  13.         public Button Button;
  14.  
  15.         ShopManager shopManager;
  16.  
  17.         void Start()
  18.         {
  19.             ButtonText.text = $"Buy for {ItemCost}";
  20.             if (PlayerPrefs.HasKey(ItemName))
  21.                 ItemCount = Load();
  22.             ImageText.text = $"{ItemName}";
  23.             if (ItemCount > 0)
  24.             {
  25.                 Button.interactable = false;
  26.                 ButtonText.text = "Куплено";
  27.             }
  28.             shopManager = FindObjectOfType<ShopManager>();
  29.         }
  30.  
  31.         public int Load()
  32.         {
  33.             return PlayerPrefs.GetInt(ItemName);
  34.         }
  35.  
  36.         public void Save()
  37.         {
  38.             PlayerPrefs.SetInt(ItemName, ItemCount);
  39.             Debug.Log("Сохранение прошло успешно!");
  40.         }
  41.  
  42.         public void OnClickBuy()
  43.         {
  44.             shopManager.BuyItem(this);
  45.         }
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top