-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalogy.cs
46 lines (38 loc) · 1.06 KB
/
Analogy.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Analogy : MonoBehaviour {
public RectTransform handle;
public RectTransform rect;
public Transform player;
private bool dragging = false;
private static Analogy _instance;
public static Analogy Instance {
get { return _instance; }
}
void Awake()
{
_instance = this;
}
private void Update()
{
Drage();
}
public void StartDrag() {
dragging = true;
}
public Vector2 Drage() {
if (!dragging) { return new Vector2(0,0); }
Vector2 mPos = Input.mousePosition;
Vector2 newPos = mPos - rect.anchoredPosition;
Vector2 pos = Vector2.ClampMagnitude(newPos,70);
handle.anchoredPosition = pos;
Vector2 dir = pos.normalized* 60 * Time.deltaTime;
print(dir);
return dir;
}
public void StopDrage() {
dragging = false;
handle.anchoredPosition = Vector2.zero;
}
}