質問編集履歴
1
メインカメラにアタッチしているスクリプトを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,48 @@
|
|
9
9
|
```ここに言語を入力
|
10
10
|
_sphere = Instantiate (_spherePref,this.transform.position, _spherePref.transform.rotation) as GameObject;
|
11
11
|
_sphere.name = _spherePref.name;
|
12
|
+
```
|
13
|
+
|
14
|
+
追記事項
|
15
|
+
メインカメラに下記のスクリプトをアタッチしています。
|
16
|
+
```using UnityEngine;
|
17
|
+
using System.Collections;
|
18
|
+
|
19
|
+
public class gyro : MonoBehaviour {
|
20
|
+
|
21
|
+
// 自信のTransform, 毎フレーム参照すると無駄なので保持する
|
22
|
+
Transform m_transform;
|
23
|
+
|
24
|
+
// 調整値
|
25
|
+
readonly Quaternion _BASE_ROTATION = Quaternion.Euler(90, 0, 0);
|
26
|
+
|
27
|
+
void Start()
|
28
|
+
{
|
29
|
+
// サポートするかの確認
|
30
|
+
if (!SystemInfo.supportsGyroscope || UnityEngine.VR.VRSettings.enabled)
|
31
|
+
{
|
32
|
+
Debug.Log ("未サポート");
|
33
|
+
Destroy( this );
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
Input.gyro.enabled = true;
|
38
|
+
if (Input.gyro.enabled)
|
39
|
+
{
|
40
|
+
Quaternion gyro = Input.gyro.attitude;
|
41
|
+
this.transform.localRotation = Quaternion.Euler(0, 0, 0) * (new Quaternion(-gyro.x,-gyro.y, gyro.z, gyro.w));
|
42
|
+
}
|
43
|
+
|
44
|
+
m_transform = transform;
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
void Update()
|
49
|
+
{
|
50
|
+
Quaternion gyro = Input.gyro.attitude;
|
51
|
+
m_transform.localRotation = _BASE_ROTATION * (new Quaternion(-gyro.x, -gyro.y, gyro.z, gyro.w));
|
52
|
+
}
|
53
|
+
|
54
|
+
}
|
55
|
+
|
12
56
|
```
|