So I’m working on a game in which you drag & drop a card (image) into another image which is the “dropzone” I need a script that will destroy the card when dropped into the dropzone.
If you are using IDraggable IBeginDrag IEndDrag and IDropHandler interfaces then there is a function on your dropzone called OnDrop(pointereventdata event) ---- event.pointerDrag is gonna give you an object which is being dropped on your dropzone. If you are using a different approach you should also have something similar
From here how would I destroy
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DropZone : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler {
public void OnPointerEnter(PointerEventData eventData) {
//Debug.Log ("OnPointerEnter");
}
public void OnPointerExit(PointerEventData eventData) {
//Debug.Log ("OnPointerExit");
}
public void OnDrop(PointerEventData eventData) {
Debug.Log (eventData.pointerDrag.name + " was dropped on " + gameObject.name);
Drag d = eventData.pointerDrag.GetComponent<Drag> ();
if (d != null) {
d.parentToReturnTo = this.transform;
}
}
}