Drag and Drop objects using mouse
- thetperson314
- Jun 1, 2022
- 1 min read
Updated: Apr 29, 2023
The code from the Drag and Drop tutorial
Camera cam;
Vector2 pos;
bool holding;
void Start()
{
cam = Camera.main;
}
void Update()
{
if (holding)
{
pos = cam.ScreenToWorldPoint(Input.mousePosition);
transform.position = pos;
}
}
private void OnMouseDown()
{
holding = true;
}
private void OnMouseUp()
{
holding = false;
}