Skip to content

Instantly share code, notes, and snippets.

Created April 19, 2020 18:38
What would you like to do?
Unity 2D Dragger Script
using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class Dragger : MonoBehaviour, IDragHandler
public GameObject target;
public bool dragable = true;
public float smoothTime = 0.1F;
private Vector2 velocity =;
public UnityEvent afterCollide;
public void OnDrag(PointerEventData eventData)
if (dragable)
var mousePosition = Input.mousePosition;
transform.position = Vector2.SmoothDamp(transform.position,
new Vector2(mousePosition.x, mousePosition.y), ref velocity, smoothTime);
void OnTriggerEnter2D(Collider2D col)
if ( ==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment