Last active
April 29, 2020 02:02
-
-
Save maxoja/87aba8b235b16f846112cce0d3dba3cb to your computer and use it in GitHub Desktop.
Unity Tutorial Source Code : Drag Object with Mouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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