Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- //Script by Andriy Skyba
- namespace FeelkepStudio
- {
- public class ShopManager : MonoBehaviour
- {
- public int Money;
- private void Start()
- {
- if (PlayerPrefs.HasKey("Money"))
- Money = LoadMoney();
- }
- public void BuyItem(ItemInfo item)
- {
- if (Money >= item.ItemCost)
- {
- item.ItemCount++;
- item.ButtonText.text = "Куплено";
- item.Button.interactable = false;
- item.Save();
- Money -= item.ItemCost;
- Debug.Log($"Предмет {item.ItemName} куплен!");
- SaveMoney();
- }
- else
- {
- Debug.Log($"Не хватает {item.ItemCost - Money} монет.");
- }
- }
- public void SaveMoney()
- {
- PlayerPrefs.SetInt("Money", Money);
- }
- public int LoadMoney()
- {
- return PlayerPrefs.GetInt("Money");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement