I', going to share my drang n drop code and you can work it out from there. Here it is :
using UnityEngine;
using UnityEngine.EventSystems;
public class DropZone : MonoBehaviour, IDropHandler
{
public void OnDrop(PointerEventData eventData)
{
Debug.Log (eventData.pointerDrag.name + " was dropped on " + gameObject.name);
//Do checks for what is being drop here
}
}
Then for the actual item we want to drag we use this:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Draggable : MonoBehaviour,
IBeginDragHandler, IDragHandler, IEndDragHandler {
public void OnBeginDrag(PointerEventData eventData) {}
public void OnDrag(PointerEventData eventData) {
//Debug.Log ("OnDrag");
transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData) {}
}
For more infromation,solutions and a in-depth look into this problem you can refer to this question on stackoverflow.