-
Notifications
You must be signed in to change notification settings - Fork 1
/
RotateTarget.cs
55 lines (45 loc) · 1.6 KB
/
RotateTarget.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
53
54
55
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class RotateTarget : MonoBehaviour , IPointerDownHandler
{
public Transform target;
public float speed = 10;
public bool isMouseDown = false;
private Vector3 lastPosition;
public float angle = 30f;
public float distance = 2f;
public bool click_scor = false;
Quaternion q = Quaternion.identity;
void Update ()
{
if (Input.GetMouseButtonDown(0) && click_scor == false)
{
isMouseDown = true;
lastPosition = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0))
{
isMouseDown = false;
click_scor = false;
GameObject tmp = GameObject.Find("Rotate");
tmp.GetComponent<RotateTarget>().enabled = true;
}
if (isMouseDown && Input.mousePosition != lastPosition && click_scor==false)
{
if (target == null)
return ;
Vector3 offset = Input.mousePosition - lastPosition;
target.localRotation = Quaternion.Euler(offset.y * Time.deltaTime * speed, -offset.x * Time.deltaTime * speed, 0) * target.localRotation;
lastPosition = Input.mousePosition;
}
}
public void OnPointerDown(PointerEventData eventData)
{
if (gameObject.name == "Scrollbar") {
click_scor = true;
GameObject tmp = GameObject.Find("Rotate");
tmp.GetComponent<RotateTarget>().enabled = false;
}
}
}