-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemDragHandler.cs
37 lines (30 loc) · 980 Bytes
/
ItemDragHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ItemDragHandler : MonoBehaviour, IDragHandler,IDropHandler,IBeginDragHandler
{
public static GameObject itemDragging;
Transform StartParent;
Vector3 startPosition;
public void OnBeginDrag(PointerEventData eventData)
{
itemDragging = gameObject;
startPosition = transform.position;
StartParent = transform.parent;
//GetComponent<CanvasGroup>().blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
transform.position = Input.mousePosition;
}
public void OnDrop(PointerEventData eventData)
{
itemDragging = null;
//GetComponent<CanvasGroup>().blocksRaycasts = true;
if (transform.parent == StartParent)
{
transform.position = startPosition;
}
}
}