Advertisement
AppingCS

ItemInfo

Jun 1st, 2020
1,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement