-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTouch.cs
60 lines (54 loc) · 1.92 KB
/
Touch.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
56
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class AndroidTouch : MonoBehaviour
{
private Vector3 FirstPoint;
private Vector3 SecondPoint;
private float xAngle;
private float yAngle;
private float xAngleTemp;
private float yAngleTemp;
private List<RaycastResult> results = new List<RaycastResult>();
private PointerEventData ped = new PointerEventData(null);
void Start()
{
xAngle = 0;
yAngle = 0;
this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0);
}
void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
results.Clear();
ped.position = touch.position;
GameObject.Find("Canvas").GetComponent<GraphicRaycaster>().Raycast(ped, results);
if (results.Count == 0)
{
SecondPoint = touch.position;
xAngleTemp = xAngle;
yAngleTemp = yAngle;
}
}
if (touch.phase == TouchPhase.Moved)
{
results.Clear();
ped.position = touch.position;
GameObject.Find("Canvas").GetComponent<GraphicRaycaster>().Raycast(ped, results);
if (results.Count == 0)
{
FirstPoint = touch.position;
xAngle = xAngleTemp + (SecondPoint.x - FirstPoint.x) * 180 / Screen.width;
yAngle = yAngleTemp + (SecondPoint.y - FirstPoint.y) * 90 / Screen.height;
yAngle = Mathf.Clamp(yAngle, -50f, 66f);
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(yAngle, xAngle, 0.0f), Time.deltaTime * 20f);
}
}
}
}
}