Drag And Drop An Object Using Unity3D

If you want to Drag And Drop an object using unity3D this C# Script will help you.

Add this script to the object that you want to drag and drop. Don’t forget to add a collider.

using UnityEngine;

public class DragAndDrop : MonoBehaviour
{
    bool selected;

    void Update()
    {

        if (selected)
        {
            Vector2 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            transform.position = new Vector2(cursorPos.x, cursorPos.y);
        }

    }

    void OnMouseDown()
    {
        selected = true;
        
    }

    void OnMouseUp()
    {
        selected = false;
    }
}

 

For more: Click Here