Advertisement
Guest User

Item.cs

a guest
Jan 31st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Item : Interactable
  4. {
  5.     [SerializeField] private ItemData m_itemData;
  6.  
  7.     protected override void OnInteracted(GameObject interactor)
  8.     {
  9.         base.OnInteracted(interactor);
  10.  
  11.         Inventory inv = interactor.GetComponent<Inventory>();
  12.         if (inv != null)
  13.             OnPicked(inv);
  14.         else
  15.             Debug.LogWarning("Failed to pick item because the picker doesn't have a Inventory component.");
  16.     }
  17.  
  18.     protected virtual void OnPicked(Inventory pickerInv)
  19.     {
  20.         if (pickerInv.AddItem(m_itemData))
  21.         {
  22.             Destroy(gameObject);
  23.         }
  24.         else
  25.         {
  26.             Debug.LogWarning("Cannot pick item, AddItem returned false. (Inventory full?)");
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement