- Home /
Question by
coveirinho00 · Feb 21, 2020 at 01:57 AM ·
c#unity 5unityui
Drag and Drop no longer lets me parent the obj iconto previous slot
Im having a problem were i have the HotbarUI with 8 slots, and when i drag the icon for example, to slot3, i cant drag it back to slot1 or slot2
Here is the Code:
//////Icon Code:
public class ItemDragHandler : MonoBehaviour, IDragHandler, IEndDragHandler { private CanvasGroup canvasGroup;
public void OnBeginDrag(PointerEventData eventData)
{
canvasGroup.blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
transform.position = Input.mousePosition;
}
public void OnEndDrag(PointerEventData eventData)
{
transform.localPosition = Vector3.zero;
canvasGroup.blocksRaycasts = true;
}
// Start is called before the first frame update
void Awake()
{
canvasGroup = GetComponent<CanvasGroup>();
}
/////Slot Code:
public class ItemDropHandler : MonoBehaviour, IDropHandler { public bool isFull;
public void OnDrop(PointerEventData eventData)
{
if(eventData.pointerDrag != null)
{
eventData.pointerDrag.GetComponent<RectTransform>().SetParent(GetComponent<RectTransform>().gameObject.transform);
}
}
Comment