Skip to content

Instantly share code, notes, and snippets.

@smkplus
Created December 4, 2019 20:26
Show Gist options
  • Save smkplus/eeab649be8d64d223d91fc520a72d168 to your computer and use it in GitHub Desktop.
Save smkplus/eeab649be8d64d223d91fc520a72d168 to your computer and use it in GitHub Desktop.
ScreenSpaceDragAndDrop
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScreenspaceDragDrop : MonoBehaviour
{

    public Camera mCamera;
    public Canvas canvas;

    // Update is called once per frame
    void Update()
    {
        var screenMousePositionPoint = Input.mousePosition;
        screenMousePositionPoint.z = canvas.planeDistance;
        transform.position = mCamera.ScreenToWorldPoint(screenMousePositionPoint);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment