質問編集履歴
1
記載漏れを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,6 +46,90 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
using System.Collections;
|
50
|
+
|
51
|
+
using System.Collections.Generic;
|
52
|
+
|
53
|
+
using UnityEngine;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
public class PlayC : MonoBehaviour
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
public float speed = 5;
|
62
|
+
|
63
|
+
Rigidbody2D rb2d;
|
64
|
+
|
65
|
+
private Animator anim;
|
66
|
+
|
67
|
+
private SpriteRenderer spRenderer;
|
68
|
+
|
69
|
+
// Start is called before the first frame update
|
70
|
+
|
71
|
+
void Start()
|
72
|
+
|
73
|
+
{
|
74
|
+
|
75
|
+
this.rb2d = GetComponent<Rigidbody2D>();
|
76
|
+
|
77
|
+
this.anim = GetComponent<Animator>();
|
78
|
+
|
79
|
+
this.spRenderer = GetComponent<SpriteRenderer>();
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// Update is called once per frame
|
86
|
+
|
87
|
+
void Update()
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
float x = Input.GetAxis("Horizontal");
|
92
|
+
|
93
|
+
anim.SetFloat("Speed", Mathf.Abs(x*speed));
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
if (x < 0)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
spRenderer.flipx = true;
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
else if (x > 0)
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
spRenderer.flipx = false;
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
rb2d.AddForce(Vector2.right *x* speed);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
49
133
|
### 試したこと
|
50
134
|
|
51
135
|
|