質問編集履歴
2
iOSでの実装でも試してみたため
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
|
14
14
|
〇使用スクリプト
|
15
15
|
以下の2種類のスクリプトで試してみました。
|
16
|
+
上のスクリプトはiOSでも動きませんでした。
|
16
17
|
|
17
18
|
```C#
|
18
19
|
using System.Collections;
|
1
内容がわかりにくかったため変更しました
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Android端末でビルドするとジャイロセンサーが反応しない
|
1
|
+
Android端末でビルドするとジャイロセンサーが反応しない
|
body
CHANGED
@@ -1,5 +1,78 @@
|
|
1
|
-
|
1
|
+
Android端末でVR開発を行っています。
|
2
|
-
シーン内にGvrEditorEmulatorをいれているので、ジャイロセンサー対応の端末にビルドするとジャイロを認識して動いてくれると認識していたのですが端末にビルドすると全く動きません。PC上で実行ボタンを起こして確認(Alt+マウス移動)するのはうまくいきます。なにがだめなのでしょうか、、、説明がわかりづらいかもしれませんがよろしくお願い致します。
|
3
|
-
|
2
|
+
360度パノラマ画像を見まわすため、ジャイロセンサーに対応させたいと思っております。
|
3
|
+
そこでUnity内のMain Cameraにジャイロセンサーに対応させるスクリプトを紐づけてビルドを行ってみました。
|
4
|
+
しかしうまく動きませんでした。
|
5
|
+
端末の問題かと思いiOSでも行うと、こちらはうまく動きました。
|
6
|
+
AndoridとiOSで記述すべき内容が違うのでしょうか。それともAndroid端末のほうで何か設定がいるのでしょうか。
|
7
|
+
宜しくお願いします。
|
4
8
|
|
9
|
+
〇使用端末
|
10
|
+
・Sony Expesia XZ 601SO
|
11
|
+
・iPhone8
|
5
|
-
ちなみに、端末は
|
12
|
+
(ちなみに、Android端末のほうはgyrocenserの対応はしています。他のアプリで確認しました。)
|
13
|
+
|
14
|
+
〇使用スクリプト
|
15
|
+
以下の2種類のスクリプトで試してみました。
|
16
|
+
|
17
|
+
```C#
|
18
|
+
using System.Collections;
|
19
|
+
using System.Collections.Generic;
|
20
|
+
using UnityEngine;
|
21
|
+
|
22
|
+
public class gyro : MonoBehaviour
|
23
|
+
{
|
24
|
+
// Start is called before the first frame update
|
25
|
+
void Start()
|
26
|
+
{
|
27
|
+
Input.gyro.enabled = true;
|
28
|
+
}
|
29
|
+
|
30
|
+
// Update is called once per frame
|
31
|
+
private void UpdateGyroData()
|
32
|
+
{
|
33
|
+
double pitch = Input.gyro.rotationRate.x;
|
34
|
+
double yaw = Input.gyro.rotationRate.y;
|
35
|
+
double roll = Input.gyro.rotationRate.z;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
```C#
|
42
|
+
using System.Collections;
|
43
|
+
using System.Collections.Generic;
|
44
|
+
using UnityEngine;
|
45
|
+
|
46
|
+
public class jairo_camera : MonoBehaviour
|
47
|
+
|
48
|
+
{// 自信のTransform, 毎フレーム参照すると無駄なので保持する
|
49
|
+
Transform m_transform;
|
50
|
+
|
51
|
+
// 調整値
|
52
|
+
readonly Quaternion _BASE_ROTATION = Quaternion.Euler(90, 0, 0);
|
53
|
+
|
54
|
+
void Start()
|
55
|
+
{
|
56
|
+
// サポートするかの確認
|
57
|
+
if (!SystemInfo.supportsGyroscope)
|
58
|
+
{
|
59
|
+
Destroy(this);
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
|
63
|
+
m_transform = transform;
|
64
|
+
}
|
65
|
+
|
66
|
+
// Update is called once per frame
|
67
|
+
void Update()
|
68
|
+
{
|
69
|
+
// ジャイロの値を獲得する
|
70
|
+
Quaternion gyro = Input.gyro.attitude;
|
71
|
+
|
72
|
+
// 自信の回転をジャイロを元に調整して設定する
|
73
|
+
m_transform.localRotation = _BASE_ROTATION * (new Quaternion(-gyro.x, -gyro.y, gyro.z, gyro.w));
|
74
|
+
}
|
75
|
+
|
76
|
+
}
|
77
|
+
|
78
|
+
```
|