I want to drag a plane around in world space, and the script does work so far, but the plane always jumps with its center to the mouse position. I want to grap it just anywhere in it and then drag it to another position and again. I guess, I have to calculate an offset, but have no idea how to do this – I tried a lot, can´t get it… I attached this to a plane
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class drag : MonoBehaviour {
private Vector3 mousePosition;
private Vector3 pos;
bool dragit;
float dist = 10;
private void OnMouseDown()
{
dragit = true;
}
private void OnMouseDrag()
{
mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist);
pos = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = pos;
}
private void OnMouseUp()
{
dragit = false;
}
}