celinedrules

InventorySlot

Apr 17th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using UnityEngine.UI;
  6.  
  7. public class InventorySlot : MonoBehaviour
  8. {
  9.     [SerializeField] private TextMeshProUGUI itemNumberText;
  10.     [SerializeField] private Image itemImage;
  11.     [SerializeField] private InventoryItem item;
  12.     [SerializeField] private InventoryManager manager;
  13.     [SerializeField] private Image selectedSprite;
  14.     [SerializeField] private bool isSelected;
  15.  
  16.     public Image SelectedSprite { get => selectedSprite; set => selectedSprite = value; }
  17.     public bool IsSelected { get => isSelected; set => isSelected = value; }
  18.     public InventoryItem Item { get => item; set => item = value; }
  19.  
  20.     public void Setup(InventoryItem item, InventoryManager manager)
  21.     {
  22.         this.item = item;
  23.         this.manager = manager;
  24.  
  25.         if(item != null)
  26.         {
  27.             itemImage.sprite = item.ItemImage;
  28.  
  29.             if (item.NumHeld > 1)
  30.                 itemNumberText.text = item.NumHeld.ToString();
  31.             else
  32.                 itemNumberText.text = "";
  33.         }
  34.     }
  35.  
  36.     public void ClickedOn()
  37.     {
  38.         if (item != null)
  39.             manager.ChangeSelectedItem(this);
  40.     }
  41. }
Add Comment
Please, Sign In to add comment