teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

追記

2019/08/26 04:53

投稿

Y0241-N
Y0241-N

スコア1066

title CHANGED
File without changes
body CHANGED
@@ -236,4 +236,113 @@
236
236
  }
237
237
  }
238
238
  }
239
+ ```
240
+
241
+ ##追記(新しいカメラのスクリプト)
242
+
243
+ ```cs
244
+ using System.Collections;
245
+ using System.Collections.Generic;
246
+ using UnityEngine;
247
+ using UnityEngine.EventSystems;
248
+ using UnityEngine.UI;
249
+ using DG.Tweening;
250
+
251
+ public class CamContorl : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler
252
+ {
253
+ public GameObject MainCamera;
254
+ public GameObject TargetObject;
255
+
256
+ private Vector3 lastMousePosition;
257
+ private Vector2 lastTouchPosition;
258
+ private Vector3 newAngle = new Vector3(0, 0, 0);
259
+ public Text text1;
260
+ public Text text2;
261
+
262
+ int touchID = -10;
263
+ bool doble = false;
264
+ double clickTimeAt;
265
+ // ダブルクリックと判定するクリック間隔
266
+ double asDoubleClickTime = 0.2;
267
+ public void Start()
268
+ {
269
+ DOTween.Init(false, true, LogBehaviour.ErrorsOnly);
270
+ clickTimeAt = Time.time;
271
+ }
272
+ public void OnBeginDrag(PointerEventData eventData)
273
+ {
274
+ if(touchID == -10)
275
+ {
276
+ touchID = eventData.pointerId;
277
+ }
278
+ }
279
+
280
+ public void OnEndDrag(PointerEventData eventData)
281
+ {
282
+ if(touchID == eventData.pointerId)
283
+ {
284
+ touchID = -10;
285
+ }
286
+ }
287
+
288
+ public void OnPointerDown(PointerEventData eventData)
289
+ {
290
+ if (Input.GetMouseButtonDown(0)) // エディタで実行中
291
+ {
292
+
293
+ // キーを押した間隔を時間から算出
294
+ double interval = Time.time - clickTimeAt;
295
+ text1.text = ("time:" + clickTimeAt.ToString("f2"));
296
+ text2.text = ("click:" + interval.ToString("f2"));
297
+
298
+ // 間隔がダブルクリック判定時間以下であれば
299
+ if (interval < asDoubleClickTime)
300
+ {
301
+ doble = true;
302
+ }
303
+ // クリックした時間を保存
304
+ clickTimeAt = Time.time;
305
+
306
+ }
307
+ newAngle = MainCamera.transform.localEulerAngles;
308
+ lastMousePosition = Input.mousePosition;
309
+ }
310
+
311
+ public void OnPointerUp(PointerEventData eventData)
312
+ {
313
+ lastMousePosition = Input.mousePosition;
314
+ }
315
+
316
+ public void OnDrag(PointerEventData eventData)
317
+ {
318
+ if (DCTF.doble == true)return;
319
+ else
320
+ {
321
+ if(lastMousePosition.y >= Screen.height * 0.28f || lastMousePosition.x >= Screen.width * 0.25f)
322
+ {
323
+ newAngle.y += (Input.mousePosition.x - lastMousePosition.x) * 0.01f;
324
+ newAngle.x -= (Input.mousePosition.y - lastMousePosition.y) * 0.01f;
325
+
326
+ newAngle.x = Mathf.Clamp(newAngle.x, -60, 60);//ここ
327
+
328
+ MainCamera.gameObject.transform.localEulerAngles = newAngle;
329
+ }
330
+ }
331
+ }
332
+
333
+ void Update()
334
+ {
335
+
336
+ if (doble == true)
337
+ {
338
+ Quaternion RY2 = TargetObject.transform.rotation;
339
+ RY2.z = 0;
340
+ RY2.x = 0;
341
+ TargetObject.transform.DORotateQuaternion(RY2,0.3f)
342
+
343
+ .OnComplete(() => doble = false);
344
+
345
+ }
346
+ }
347
+ }
239
348
  ```

2

誤字修正

2019/08/26 04:53

投稿

Y0241-N
Y0241-N

スコア1066

title CHANGED
File without changes
body CHANGED
@@ -4,7 +4,7 @@
4
4
  指一本で移動か、カメラの操作か、どちらか一方の操作なら問題なく動くのですが、
5
5
  指二本以上で移動とカメラの操作を同時に行おうとすると、様々な問題が発生します。
6
6
 
7
- こちらで実際にお試しいただます。タッチ可能デバイスで稼働してください。
7
+ こちらで実際にお試しいただます。タッチ可能デバイスで稼働してください。
8
8
  [**touch test**](https://unityroom.com/games/tuchtest)
9
9
  操作方法は左下のスティックで移動、画面タッチ&ドラッグでカメラ回転、ダブルタッチで縦回転リセットです。
10
10
  .

1

誤字修正

2019/08/20 09:03

投稿

Y0241-N
Y0241-N

スコア1066

title CHANGED
File without changes
body CHANGED
@@ -197,34 +197,33 @@
197
197
  }
198
198
  public void Update ()
199
199
  {
200
- if (Input.touchCount > 0) // タッチされているかチェック
200
+ if (Input.touchCount > 0) // タッチされているかチェック
201
- {
201
+ {
202
- Touch touch = Input.GetTouch(0); // タッチ情報の取得
202
+ Touch touch = Input.GetTouch(0); // タッチ情報の取得
203
203
 
204
- if (touch.phase == TouchPhase.Began)
204
+ if (touch.phase == TouchPhase.Began)
205
- {
205
+ {
206
- newAngle = MainCamera.transform.localEulerAngles;
206
+ newAngle = MainCamera.transform.localEulerAngles;
207
- lastTouchPosition = touch.position;
207
+ lastTouchPosition = touch.position;
208
- }
208
+ }
209
209
 
210
- if (touch.phase == TouchPhase.Moved)
210
+ if (touch.phase == TouchPhase.Moved)
211
- {
211
+ {
212
- if (DCTF.doble == true)return;
212
+ if (DCTF.doble == true)return;
213
- else
213
+ else
214
- {
214
+ {
215
- if(lastTouchPosition.y >= Screen.height * 0.28f || lastTouchPosition.x >= Screen.width * 0.25f)
215
+ if(lastTouchPosition.y >= Screen.height * 0.28f || lastTouchPosition.x >= Screen.width * 0.25f)
216
- {
216
+ {
217
- newAngle.y += (touch.position.x - lastTouchPosition.x) * 0.1f;
217
+ newAngle.y += (touch.position.x - lastTouchPosition.x) * 0.1f;
218
- newAngle.x -= (touch.position.y - lastTouchPosition.y) * 0.1f;
218
+ newAngle.x -= (touch.position.y - lastTouchPosition.y) * 0.1f;
219
- MainCamera.gameObject.transform.localEulerAngles = newAngle;
219
+ MainCamera.gameObject.transform.localEulerAngles = newAngle;
220
220
 
221
- lastTouchPosition = touch.position;
221
+ lastTouchPosition = touch.position;
222
- }
222
+ }
223
- }
223
+ }
224
- }
224
+ }
225
- }
225
+ }
226
- }
226
+
227
-
228
227
  if (DCTF.doble == true)
229
228
  {
230
229
  Quaternion RY2 = TargetObject.transform.rotation;