Pro_Unit

Product Example

Aug 19th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [CreateAssetMenu]
  4. public class Product : ScriptableObject
  5. {
  6.     [SerializeField] string _name;
  7.     [SerializeField] int _price;
  8.     [SerializeField] Sprite _icon;
  9.     // куплен или нет
  10.     public bool Bougth
  11.     {
  12.         get { return PlayerPrefs.GetInt ($"{name} bougth") == 1; }
  13.         set { PlayerPrefs.SetInt ($"{name} bougth", value ? 1 : 0); }
  14.     }
  15.     public string Name => _name;
  16.     public Sprite Icon => _icon;
  17.     public int Price => _price;
  18.  
  19.     public bool TryBuy (int money)
  20.     {
  21.         Bougth = (money - _price >= 0);
  22.  
  23.         return Bougth;
  24.     }
  25. }
Add Comment
Please, Sign In to add comment