evelynshilosky

ItemSlot - Part 5

Jun 2nd, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 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.  
  29.     public void OnDrop(PointerEventData eventData)
  30.     {
  31.         Debug.Log("OnDrop");
  32.  
  33.         //if there is not item already then set our item.
  34.         if (!Item)
  35.         {
  36.  
  37.             DragDrop.itemBeingDragged.transform.SetParent(transform);
  38.             DragDrop.itemBeingDragged.transform.localPosition = new Vector2(0, 0);
  39.  
  40.         }
  41.  
  42.  
  43.     }
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
Add Comment
Please, Sign In to add comment