AppingCS

ShopControll

Jul 11th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. //Script by Andriy Skyba
  6. public class ShopControll : MonoBehaviour
  7. {
  8.     [SerializeField] private int Money;
  9.     [SerializeField] private Text money_text;
  10.     private void Start()
  11.     {
  12.         if (!PlayerPrefs.HasKey("Money"))
  13.         {
  14.             PlayerPrefs.SetInt("Money", 1000);
  15.         }
  16.         Money = PlayerPrefs.GetInt("Money");
  17.     }
  18.     private void Update()
  19.     {
  20.         money_text.text = "Монет : " + Money;
  21.         PlayerPrefs.SetInt("Money", Money);
  22.     }
  23.     public void Item1(ItemInfo item)
  24.     {
  25.         if(Money >= item.cost)
  26.         {
  27.             Money -= item.cost;
  28.             item.this_Item.interactable = false;
  29.             item.this_Item.GetComponentInChildren<Text>().text = "Куплено";
  30.             Debug.LogWarning("С вашего счёта было списано " + item.cost + " монет");
  31.             Debug.Log("Вы купили предмет " + item._name);
  32.             PlayerPrefs.SetInt(item._name, 1);
  33.         } else if(Money < item.cost)
  34.         {
  35.             Debug.Log("У вас нет денег");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment