質問編集履歴

1

メインカメラにアタッチしているスクリプトを追記

2016/10/05 01:49

投稿

Qoo
Qoo

スコア1249

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,91 @@
21
21
  _sphere.name = _spherePref.name;
22
22
 
23
23
  ```
24
+
25
+
26
+
27
+ 追記事項
28
+
29
+ メインカメラに下記のスクリプトをアタッチしています。
30
+
31
+ ```using UnityEngine;
32
+
33
+ using System.Collections;
34
+
35
+
36
+
37
+ public class gyro : MonoBehaviour {
38
+
39
+
40
+
41
+ // 自信のTransform, 毎フレーム参照すると無駄なので保持する
42
+
43
+ Transform m_transform;
44
+
45
+
46
+
47
+ // 調整値
48
+
49
+ readonly Quaternion _BASE_ROTATION = Quaternion.Euler(90, 0, 0);
50
+
51
+
52
+
53
+ void Start()
54
+
55
+ {
56
+
57
+ // サポートするかの確認
58
+
59
+ if (!SystemInfo.supportsGyroscope || UnityEngine.VR.VRSettings.enabled)
60
+
61
+ {
62
+
63
+ Debug.Log ("未サポート");
64
+
65
+ Destroy( this );
66
+
67
+ return;
68
+
69
+ }
70
+
71
+
72
+
73
+ Input.gyro.enabled = true;
74
+
75
+ if (Input.gyro.enabled)
76
+
77
+ {
78
+
79
+ Quaternion gyro = Input.gyro.attitude;
80
+
81
+ this.transform.localRotation = Quaternion.Euler(0, 0, 0) * (new Quaternion(-gyro.x,-gyro.y, gyro.z, gyro.w));
82
+
83
+ }
84
+
85
+
86
+
87
+ m_transform = transform;
88
+
89
+
90
+
91
+ }
92
+
93
+
94
+
95
+ void Update()
96
+
97
+ {
98
+
99
+ Quaternion gyro = Input.gyro.attitude;
100
+
101
+ m_transform.localRotation = _BASE_ROTATION * (new Quaternion(-gyro.x, -gyro.y, gyro.z, gyro.w));
102
+
103
+ }
104
+
105
+
106
+
107
+ }
108
+
109
+
110
+
111
+ ```