Advertisement
AppingCS

ShopManager

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