Question by
MegaRfenixXD · Sep 21, 2018 at 05:15 PM ·
drag and dropslotpaste
Problem with slots [Album of cards]
The drag and drop is done and paste like figures but it is not a method to leave as fixed figures for a specific slot Would anyone know to answer a way to leave the figure fixed to that slot?
Script:DragHandler
public void OnBeginDrag(PointerEventData eventData)
{
itemBeingDragged = gameObject;
startPosition = transform.position;
startParent = transform.parent;
GetComponent<CanvasGroup>().blocksRaycasts = false;
canvas = GameObject.FindGameObjectWithTag("UI Canvas").transform;
transform.parent = canvas;
}
public void OnDrag(PointerEventData eventData)
{
RectTransformUtility.ScreenPointToWorldPointInRectangle(this.GetComponent<RectTransform>(), eventData.position, eventData.enterEventCamera, out startPosition);
transform.position = startPosition;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log(transform.parent + " == " + canvas);
itemBeingDragged = null;
GetComponent<CanvasGroup>().blocksRaycasts = true;
if (transform.parent == canvas)
{
transform.position = startPosition;
transform.parent = startParent;
}
}
Script:Slot
public GameObject item{
get
{
if (transform.childCount > 0)
{
return transform.GetChild(0).gameObject;
}
return null;
}
}
#region IDropMandler Implementation
public void OnDrop (PointerEventData eventData)
{
if (!item)
{
DragHandler.itemBeingDragged.transform.SetParent(transform);
}
}
#endregion
Comment