Advertisement
evelynshilosky

ItemSlot - Part 12

Jun 4th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5.  
  6.  
  7.  
  8. public class ItemSlot : MonoBehaviour, IDropHandler
  9. {
  10.  
  11.     public GameObject Item
  12.     {
  13.         get
  14.         {
  15.             if (transform.childCount > 0)
  16.             {
  17.                 return transform.GetChild(0).gameObject;
  18.             }
  19.  
  20.             return null;
  21.         }
  22.     }
  23.  
  24.  
  25.  
  26.  
  27.  
  28.         public void OnDrop(PointerEventData eventData)
  29.     {
  30.  
  31.         //if there is not item already then set our item.
  32.         if (!Item)
  33.         {
  34.  
  35.             DragDrop.itemBeingDragged.transform.SetParent(transform);
  36.             DragDrop.itemBeingDragged.transform.localPosition = new Vector2(0, 0);
  37.  
  38.             if (!transform.CompareTag("QuickSlot"))
  39.             {
  40.                 DragDrop.itemBeingDragged.GetComponent<InventoryItem>().isInsideQuickSlots = false;
  41.                 InventorySystem.Instance.ReCalculateList();
  42.             }
  43.  
  44.             if (transform.CompareTag("QuickSlot"))
  45.             {
  46.                 DragDrop.itemBeingDragged.GetComponent<InventoryItem>().isInsideQuickSlots = true;
  47.                 InventorySystem.Instance.ReCalculateList();
  48.             }
  49.  
  50.         }
  51.  
  52.  
  53.     }
  54.  
  55.  
  56.  
  57.  
  58. }
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement