質問編集履歴

2

文章の補足

2017/09/01 02:44

投稿

tottyan
tottyan

スコア14

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  unityのcardboard GoogleVRで
4
4
 
5
- InputTracking.disablePositionalTrackingを使ってカメラを起動時に固定す。できるのであるのなら他の方法でもかまいません。
5
+ InputTracking.disablePositionalTrackingを使ってカメラを起動時に固定したいです。できるのであるのなら他の方法でもかまいません。
6
+
7
+ 回答よろしくお願いします。
6
8
 
7
9
 
8
10
 

1

コードの追加

2017/09/01 02:44

投稿

tottyan
tottyan

スコア14

test CHANGED
File without changes
test CHANGED
@@ -118,10 +118,20 @@
118
118
 
119
119
  以下VRカメラの親のオブジェクトのスクリプト
120
120
 
121
- ・スマホの方向から
121
+
122
122
 
123
123
  ```C#
124
124
 
125
+ //3Dシューティングゲームのカメラの親ゲームオブジェクトのソースコードです
126
+
127
+
128
+
129
+ //カメラの位置を引く
130
+
131
+ using System.Collections;
132
+
133
+ using System.Collections.Generic;
134
+
125
135
  using UnityEngine;
126
136
 
127
137
  using UnityEngine.VR;
@@ -152,6 +162,80 @@
152
162
 
153
163
  //カメラが今向いてる向きを取得
154
164
 
165
+ kamera = GameObject.FindWithTag("MainCamera");
166
+
167
+ //反転させる
168
+
169
+ Quaternion hanten=Quaternion.Euler(-kamera.transform.rotation.x,-kamera.transform.rotation.y,kamera.transform.rotation.z);
170
+
171
+ transform.rotation = hanten;
172
+
173
+ }
174
+
175
+
176
+
177
+ // Update is called once per frame
178
+
179
+ int count;
180
+
181
+ void Update()
182
+
183
+ {
184
+
185
+ //プレイヤー機にカメラが追従するようになっている
186
+
187
+ if (GameObject.FindWithTag("player") == true)
188
+
189
+ {
190
+
191
+ Vector3 vecP = GameObject.FindWithTag("player").transform.position;
192
+
193
+ Vector3 vec3 = transform.position;
194
+
195
+ vec3.z = vecP.z+differenceZ;
196
+
197
+ transform.position = vec3;
198
+
199
+ }
200
+
201
+ }
202
+
203
+ }
204
+
205
+
206
+
207
+ //スマホの方向から
208
+
209
+ using UnityEngine;
210
+
211
+ using UnityEngine.VR;
212
+
213
+ using System;
214
+
215
+
216
+
217
+ public class CameraControl : MonoBehaviour {
218
+
219
+ public Vector3 difference;
220
+
221
+ float differenceZ;
222
+
223
+
224
+
225
+ GameObject kamera;
226
+
227
+
228
+
229
+ // Use this for initialization
230
+
231
+ void Start() {
232
+
233
+ difference = transform.position;
234
+
235
+ differenceZ = difference.z;
236
+
237
+ //カメラが今向いてる向きを取得
238
+
155
239
  Vector3 trackingPos =
156
240
 
157
241
  InputTracking.GetLocalPosition(VRNode.CenterEye);