Last active
October 30, 2019 02:15
-
-
Save TheCuttlefish/5f6f84be9c152af1390bc688f78b21d3 to your computer and use it in GitHub Desktop.
Simple Drag and Drop in Unity
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; | |
public class MouseInput : MonoBehaviour { | |
Vector3 offset = new Vector3 (0, 0, 10); | |
bool follow = false; | |
void OnMouseDown () { | |
follow = true; | |
} | |
void OnMouseUp () { | |
follow = false; | |
} | |
void Update () { | |
if(follow) | |
transform.position = Camera.main.ScreenToWorldPoint (Input.mousePosition) + offset; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment