SHARE
TWEET

ShopManager

AppingCS Jun 1st, 2020 872 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. //Script by Andriy Skyba
  3. namespace FeelkepStudio
  4. {
  5.     public class ShopManager : MonoBehaviour
  6.     {
  7.         public int Money;
  8.  
  9.         private void Start()
  10.         {
  11.             if (PlayerPrefs.HasKey("Money"))
  12.                 Money = LoadMoney();
  13.         }
  14.  
  15.         public void BuyItem(ItemInfo item)
  16.         {
  17.             if (Money >= item.ItemCost)
  18.             {
  19.                 item.ItemCount++;
  20.                 item.ButtonText.text = "Куплено";
  21.                 item.Button.interactable = false;
  22.                 item.Save();
  23.                 Money -= item.ItemCost;
  24.                 Debug.Log($"Предмет {item.ItemName} куплен!");
  25.                 SaveMoney();
  26.             }
  27.             else
  28.             {
  29.                 Debug.Log($"Не хватает {item.ItemCost - Money} монет.");
  30.             }
  31.         }
  32.         public void SaveMoney()
  33.         {
  34.             PlayerPrefs.SetInt("Money", Money);
  35.         }
  36.         public int LoadMoney()
  37.         {
  38.             return PlayerPrefs.GetInt("Money");
  39.         }
  40.     }
  41. }
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