Tanoda
TouchController.cs
Go to the documentation of this file.
1using UnityEngine;
3using System.Collections;
4using System.Linq;
5
7{
8 public class TouchController : MonoBehaviour
9 {
10 public GameObject Cube;
11 public float Speed = 0.1f;
12
13 void Update ()
14 {
15 #if ((UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR)
16
17 //Touch
18 int touchCount = Input.touchCount;
19
20 if (touchCount == 1)
21 {
22
23 Touch t = Input.GetTouch(0);
24 if(EventSystem.current.IsPointerOverGameObject(t.fingerId))return;
25
26 switch (t.phase)
27 {
28 case TouchPhase.Moved:
29
30 float xAngle = t.deltaPosition.y * Speed;
31 float yAngle = -t.deltaPosition.x * Speed;
32 float zAngle = 0;
33
34 Cube.transform.Rotate(xAngle, yAngle, zAngle, Space.World);
35
36 break;
37 }
38
39 }
40
41 #else
42 //Mouse
43 if (Input.GetMouseButton (0)) {
44 if (EventSystem.current.IsPointerOverGameObject ())
45 return;
46
47 float xAngle = Input.GetAxis ("Mouse Y") * Speed * 80;
48 float yAngle = -Input.GetAxis ("Mouse X") * Speed * 80;
49 float zAngle = 0;
50
51 Cube.transform.Rotate (xAngle, yAngle, zAngle, Space.World);
52 }
53 #endif
54 }
55 }
56}