Advertisement
evelynshilosky

ItemSlot - Part 31

Feb 2nd, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 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.             SoundManager.Instance.PlaySound(SoundManager.Instance.dropItemSound);
  36.  
  37.  
  38.             DragDrop.itemBeingDragged.transform.SetParent(transform);
  39.             DragDrop.itemBeingDragged.transform.localPosition = new Vector2(0, 0);
  40.  
  41.             if (!transform.CompareTag("QuickSlot"))
  42.             {
  43.                 DragDrop.itemBeingDragged.GetComponent<InventoryItem>().isInsideQuickSlots = false;
  44.                 InventorySystem.Instance.ReCalculateList();
  45.             }
  46.  
  47.             if (transform.CompareTag("QuickSlot"))
  48.             {
  49.                 DragDrop.itemBeingDragged.GetComponent<InventoryItem>().isInsideQuickSlots = true;
  50.                 InventorySystem.Instance.ReCalculateList();
  51.             }
  52.  
  53.         }
  54.  
  55.  
  56.     }
  57.  
  58.  
  59.  
  60.  
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement