Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Last active October 30, 2019 02:15
Show Gist options
  • Save TheCuttlefish/5f6f84be9c152af1390bc688f78b21d3 to your computer and use it in GitHub Desktop.
Save TheCuttlefish/5f6f84be9c152af1390bc688f78b21d3 to your computer and use it in GitHub Desktop.
Simple Drag and Drop in Unity
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