Skip to content

Instantly share code, notes, and snippets.

@insthync
Created February 13, 2019 03:34
Show Gist options
  • Save insthync/8d4438848dcbb3a1e4268dea4873861f to your computer and use it in GitHub Desktop.
Save insthync/8d4438848dcbb3a1e4268dea4873861f to your computer and use it in GitHub Desktop.
Simple draggable window
using UnityEngine;
using UnityEngine.EventSystems;
public class DraggableWindow : MonoBehaviour, IBeginDragHandler, IDragHandler
{
private float mouseOffsetY;
private float mouseOffsetX;
public void OnBeginDrag(PointerEventData eventData)
{
mouseOffsetX = transform.position.x - Input.mousePosition.x;
mouseOffsetY = transform.position.y - Input.mousePosition.y;
}
public void OnDrag(PointerEventData eventData)
{
transform.position = new Vector3(mouseOffsetX + Input.mousePosition.x, mouseOffsetY + Input.mousePosition.y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment