Very easy to do.
public void OnDrop (PointerEventData eventData)
{
Debug.Log (eventData.pointerDrag.name + "was drop on " + gameObject.name);
Draggable d = eventData.pointerDrag.GetComponent ();//d locates the card being dropped
//Debug.Log (d.name + "es d");
if (d != null)
{
//Create a temporary Transform and search for if the child name exist
Transform foundChild = transform.Find(d.name);
//Check if the transform is not null
if(!foundChild)
{
Debug.Log ("there already is a child with this name");
d.parentToReturnTo = foundChild; //Change the parent
}
/*Must have else statement or it will run the code below even if the names are thesame.*/
else{
d.parentToReturnTo = this.transform;
}
}
}
Not tested and may not compile but this should lead you in a great direction to make it work.
↧