質問編集履歴

2

プレグラムの訂正

2018/06/23 16:38

投稿

kome-kit
kome-kit

スコア11

test CHANGED
File without changes
test CHANGED
@@ -16,39 +16,37 @@
16
16
 
17
17
 
18
18
 
19
- // 移動スピード
19
+ public float speed = 3f;
20
20
 
21
- public float speed = 5;
21
+ float moveX = 0f;
22
+
23
+ float moveY = 0f;
24
+
25
+ Rigidbody2D rb;
22
26
 
23
27
 
24
28
 
25
- void Update ()
29
+ void Start(){
26
30
 
27
- {
31
+ rb = GetComponent<Rigidbody2D> ();
28
32
 
29
- // 右・左
33
+ }
30
-
31
- float x = Input.GetAxisRaw ("Horizontal");
32
34
 
33
35
 
34
36
 
35
- // 上・下
37
+ void FixedUpdate () {
36
38
 
39
+ moveX = Input.GetAxis ("Horizontal") * speed;
40
+
37
- float y = Input.GetAxisRaw ("Vertical");
41
+ moveY = Input.GetAxis ("Vertical") * speed;
42
+
43
+ Vector2 direction = new Vector2(moveX , moveY).normalized;
44
+
45
+ rb.velocity = new Vector2(moveX, moveY);
46
+
47
+ }
38
48
 
39
49
 
40
-
41
- // 移動する向きを求める
42
-
43
- Vector2 direction = new Vector2 (x, y).normalized;
44
-
45
-
46
-
47
- // 移動する向きとスピードを代入する
48
-
49
- GetComponent<Rigidbody2D>().AddForce(direction * speed, ForceMode2D.Force);
50
-
51
- }
52
50
 
53
51
 
54
52
 

1

2Dというのを明記しました

2018/06/23 16:38

投稿

kome-kit
kome-kit

スコア11

test CHANGED
@@ -1 +1 @@
1
- Unityのcollider同士の衝突時の挙動について
1
+ Unity2Dのcollider同士の衝突時の挙動について
test CHANGED
@@ -1,4 +1,4 @@
1
- Unityでドット絵のゲームを作っています
1
+ Unity2Dでドット絵のゲームを作っています
2
2
 
3
3
 
4
4