Drag and drop scripting trouble

hi, so i grabed a script from a unity sample project thinking i could modify it a bit to get the desired result but i am having some trouble. what i want to do is drag an image from my panel and place it on my canvas drop zone and that all works fine. the problem i am having is that i would also like to be able to move the image that was dropped again if i want and for some reason i cannot get this to work. i have tried not destroying the “icon” and adding the Move me script to that as well but nothing i do seems to fix the problem

any help would be appreciated

here is the drawing scrip where i think the problem can be solved

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[RequireComponent(typeof(Image))]
public class DragMe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    public bool dragOnSurfaces = true;
   
    private GameObject m_DraggingIcon;
    private RectTransform m_DraggingPlane;
    private GameObject gameBoard;

    public void OnBeginDrag(PointerEventData eventData)
    {
        var canvas = FindInParents<Canvas>(gameObject);
        if (canvas == null)
            return;

        // We have clicked something that can be dragged.
        // What we want to do is create an icon for this.
        m_DraggingIcon = new GameObject("icon");

        m_DraggingIcon.transform.SetParent (canvas.transform,false);
        m_DraggingIcon.transform.SetAsLastSibling();
       
        var image = m_DraggingIcon.AddComponent<Image>();
        // The icon will be under the cursor.
        // We want it to be ignored by the event system.
        CanvasGroup group = m_DraggingIcon.AddComponent<CanvasGroup>();
        group.blocksRaycasts = false;

        image.sprite = GetComponent<Image>().sprite;
        image.SetNativeSize();
       
        if (dragOnSurfaces)
            m_DraggingPlane = transform as RectTransform;
        else
            m_DraggingPlane = canvas.transform as RectTransform;
       
        SetDraggedPosition(eventData);
    }

    public void OnDrag(PointerEventData data)
    {
        if (m_DraggingIcon != null)
            SetDraggedPosition(data);
    }

    private void SetDraggedPosition(PointerEventData data)
    {
        if (dragOnSurfaces && data.pointerEnter != null && data.pointerEnter.transform as RectTransform != null)
            m_DraggingPlane = data.pointerEnter.transform as RectTransform;
       
        var rt = m_DraggingIcon.GetComponent<RectTransform>();
        Vector3 globalMousePos;
        if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlane, data.position, data.pressEventCamera, out globalMousePos))
        {
            rt.position = globalMousePos;
            rt.rotation = m_DraggingPlane.rotation;
        }
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        if (m_DraggingIcon != null)
        {
            Destroy(m_DraggingIcon);
        }
           
   
    }

    static public T FindInParents<T>(GameObject go) where T : Component
    {
        if (go == null) return null;
        var comp = go.GetComponent<T>();

        if (comp != null)
            return comp;
       
        Transform t = go.transform.parent;
        while (t != null && comp == null)
        {
            comp = t.gameObject.GetComponent<T>();
            t = t.parent;
        }
        return comp;
    }
}

here is the droping script but i don’t think the problem is here

using System.Reflection;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class DropMe : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
{
    public Image containerImage;
    public Image receivingImage;
    private Color normalColor;
    public Color highlightColor = Color.yellow;
   
    public void OnEnable ()
    {
        if (containerImage != null)
            normalColor = containerImage.color;
    }
   
    public void OnDrop(PointerEventData data)
    {
        containerImage.color = normalColor;
       
        if (receivingImage == null)
            return;
       
        Sprite dropSprite = GetDropSprite (data);
        if (dropSprite != null)
            receivingImage.overrideSprite = dropSprite;
    }

    public void OnPointerEnter(PointerEventData data)
    {
        if (containerImage == null)
            return;
       
        Sprite dropSprite = GetDropSprite (data);
        if (dropSprite != null)
            containerImage.color = highlightColor;
    }

    public void OnPointerExit(PointerEventData data)
    {
        if (containerImage == null)
            return;
       
        containerImage.color = normalColor;
    }
   
    private Sprite GetDropSprite(PointerEventData data)
    {
        var originalObj = data.pointerDrag;
        if (originalObj == null)
            return null;

        var srcImage = originalObj.GetComponent<Image>();
        if (srcImage == null)
            return null;
       
        return srcImage.sprite;
    }
}

Looks like the object you began dragging from isn’t the object that you’re actually dragging. so the slot where you dropped to will also need the Drag script.

yeah i tried that, the problem with that is once an image is dragged to the drop zone if you add the drag script to that it takes the drop zone image instead of the image that i dragged there

so wait, do you have 2 Image components on the same gameobject?

the setup I usually do for Slot UI is a panel object and holds the actual empty Slot image (as the background) and then a child gameobject that is the container object. put the drag and drop scripts on the child container.

no, i have one image that is selected from a panel of images(that has the drag script on it), then its dropped on a game board that i have set up that has an a multitude of images that represent the game board and the image that represents the game board space is the one that ends up being dragged when i try to redraw the dropped image

Well you’re using GetComponent in the drag script. perhaps making that a public variable so the drag script knows which image to grab would help.