-
Notifications
You must be signed in to change notification settings - Fork 1
/
MoveCameraForGearVR.cs
96 lines (87 loc) · 2.54 KB
/
MoveCameraForGearVR.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
----------------------------------------------
--- Author : Ahmet Özlü
--- Mail : ahmetozlu93@gmail.com
--- Date : 1st August 2017
----------------------------------------------
*/
using UnityEngine;
using VRStandardAssets.Utils;
[RequireComponent(typeof (Rigidbody))]
public class OVR_RB_Player : MonoBehaviour
{
[SerializeField]
private float m_speed = 0.8f;
[SerializeField]
private VRInput m_VRInput;
private Rigidbody m_Rigidbody;
private Transform head;
private Transform body;
private int m_isWalking = 0;
private Vector3 m_direction;
void Awake()
{
m_Rigidbody = GetComponent<Rigidbody>();
head = Camera.main.transform;
body = transform.Find("Body");
}
private void OnEnable()
{
m_VRInput.OnSwipe += HandleSwipe;
m_VRInput.OnDoubleClick += HandleDoubleClick;
m_VRInput.OnCancel += HandleCancel;
}
private void OnDisable()
{
m_VRInput.OnSwipe -= HandleSwipe;
m_VRInput.OnDoubleClick -= HandleDoubleClick;
m_VRInput.OnCancel -= HandleCancel;
}
private void HandleSwipe(VRInput.SwipeDirection swipeDirection)
{
switch (swipeDirection)
{
case VRInput.SwipeDirection.NONE:
break;
case VRInput.SwipeDirection.UP:
transform.position = new Vector3(transform.position.x, 75, transform.position.z);
break;
case VRInput.SwipeDirection.DOWN:
transform.position = new Vector3(transform.position.x, 1, transform.position.z);
break;
case VRInput.SwipeDirection.LEFT:
m_isWalking += 2;
break;
case VRInput.SwipeDirection.RIGHT:
m_isWalking += -2;
break;
}
}
private void HandleDown()
{
}
private void HandleUp()
{
}
private void HandleClick() // Quits the Game by pressing Back button on Gear VR
{
}
private void HandleDoubleClick() // Stops by swiping down or double click.
{
m_isWalking = 0;
}
private void HandleCancel()
{
Application.Quit();
}
public void FixedUpdate()
{
if (m_isWalking != 0)
{
m_direction = head.forward;
m_direction.y = 0f;
m_Rigidbody.transform.Translate(m_direction * m_speed * m_isWalking * Time.fixedDeltaTime);
body.transform.rotation = Quaternion.Euler(new Vector3(0.0f, head.eulerAngles.y, 0.0f));
}
}
}