-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDragFreely.cs
52 lines (43 loc) · 1.05 KB
/
DragFreely.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DragFreely : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public static GameObject itemBeingDragged;
public Vector3 OffsetVector;
Vector3 startPosition;
public bool CanDrag;
public bool StorageInteractionLock;
public GameObject togg;
#region IBeginDragHandler implementation
public void OnBeginDrag (PointerEventData eventData)
{
itemBeingDragged = gameObject;
startPosition = transform.position;
}
#endregion
#region IDragHandler implementation
public void OnDrag (PointerEventData eventData)
{
if (CanDrag == true && StorageInteractionLock == false)
{
transform.position = Input.mousePosition - OffsetVector;
}
else
{
transform.position = startPosition;
}
}
#endregion
#region IEndDragHandler implementation
public void OnEndDrag (PointerEventData eventData)
{
itemBeingDragged = null;
}
#endregion
void ToggleDrag()
{
CanDrag = !togg.GetComponent<Toggle>().isOn;
}
}