Created
February 13, 2019 03:34
-
-
Save insthync/8d4438848dcbb3a1e4268dea4873861f to your computer and use it in GitHub Desktop.
Simple draggable window
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 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