質問編集履歴
1
回答頂いたスクリプトを適用しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -111,3 +111,101 @@
|
|
111
111
|
|
112
112
|
|
113
113
|
このスクリプトのどの部分が悪いのか、分かる方教えてください。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
------------------------------------------------------------------
|
118
|
+
|
119
|
+
下は回答頂いたスクリプトを適用したものです。
|
120
|
+
|
121
|
+
```ここに言語を入力
|
122
|
+
|
123
|
+
using System.Collections;
|
124
|
+
|
125
|
+
using System.Collections.Generic;
|
126
|
+
|
127
|
+
using UnityEngine;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
namespace CSharpScript
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
public class UnkomanControl2 : MonoBehaviour
|
138
|
+
|
139
|
+
{
|
140
|
+
|
141
|
+
float inputX;
|
142
|
+
|
143
|
+
float inputZ;
|
144
|
+
|
145
|
+
Rigidbody Rb;
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
float moveSpeed = 7f;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
void Start()
|
154
|
+
|
155
|
+
{
|
156
|
+
|
157
|
+
Rb = GetComponent<Rigidbody>();
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
void Update()
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
inputX = Input.GetAxis("Horizontal");
|
168
|
+
|
169
|
+
inputZ = Input.GetAxis("Vertical");
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
void FixedUpdate()
|
176
|
+
|
177
|
+
{
|
178
|
+
|
179
|
+
Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
|
180
|
+
|
181
|
+
Vector3 cameraRight = Vector3.Scale(Camera.main.transform.right, new Vector3(1, 0, 1)).normalized;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
Vector3 moveForward = cameraForward * inputZ + cameraRight * inputX;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
Rb.velocity = moveForward * moveSpeed + new Vector3(0, Rb.velocity.y);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
if(moveForward.magnitude != 0f)
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
transform.rotation = Quaternion.LookRotation(moveForward);
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
```
|