Skip to content

Instantly share code, notes, and snippets.

@maxoja
Last active April 29, 2020 02:02
Show Gist options
  • Save maxoja/87aba8b235b16f846112cce0d3dba3cb to your computer and use it in GitHub Desktop.
Save maxoja/87aba8b235b16f846112cce0d3dba3cb to your computer and use it in GitHub Desktop.
Unity Tutorial Source Code : Drag Object with Mouse
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//this script colaborates to the tutorial
//https://www.youtube.com/watch?v=pK1CbnE2VsI
public class MouseDrag : MonoBehaviour {
float distance = 10;
private void OnMouseDrag()
{
Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
Vector3 objectPos = Camera.main.ScreenToWorldPoint(mousePos);
transform.position = objectPos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment