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

質問編集履歴

1

書式の改善

2018/07/08 08:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -11,25 +11,22 @@
11
11
  float direction = 1f;
12
12
  Rigidbody2D rb2d;
13
13
 
14
- // Use this for initialization
15
14
  void Start () {
16
15
  rb2d = GetComponent<Rigidbody2D>();
17
16
  }
18
17
 
19
- // Update is called once per frame
20
18
  void Update () {
21
19
  if (Input.touchCount > 0) {
22
20
  Touch touch = Input.GetTouch(0);
23
- //画面右半分をタッチしていたら
21
+ //画面右半分をタッチしていたら右に移動
24
22
  if(touch.position.x > Screen.width * 0.5f) {
25
23
  direction = 1f;
26
- //画面左半分をタッチしていたら
24
+ //画面左半分をタッチしていたら左に移動
27
- }else if (touch.position.x < Screen.width * 0.5f) {
25
+ } else if (touch.position.x < Screen.width * 0.5f) {
28
26
  direction = -1f;
27
+ } else {
28
+ direction = 0f; //←何もタッチしていない場合は反応なし
29
29
  }
30
- else {
31
- direction = 0f;
32
- }
33
30
  }
34
31
  rb2d.velocity = new Vector2(scroll * direction, rb2d.velocity.y);
35
32
  }