/
DragWindow.cs
50 lines (41 loc) · 859 Bytes
/
DragWindow.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragWindow : MonoBehaviour
{
/// <summary>
/// Simple click-and-drag, but moves the actual window (if not fullscreen)
/// </summary>
new Collider2D collider = null;
bool draggingWindow = false;
void Awake()
{
collider = GetComponent<Collider2D>();
}
void Update()
{
if (!Input.GetMouseButton(0))
{
draggingWindow = false;
return;
}
if (Input.GetMouseButtonDown(0))
{
Vector2 pos = TransparentWindow.Camera.ScreenToWorldPoint(Input.mousePosition);
var overlapCollider = Physics2D.OverlapPoint(pos);
if (!overlapCollider)
{
draggingWindow = false;
return;
}
if (overlapCollider == collider)
{
draggingWindow = true;
}
}
if (draggingWindow)
{
TransparentWindow.DragWindow();
}
}
}