質問編集履歴
2
C#スクリプトの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,357 @@
|
|
33
33
|
それらしいページが見当たらないので
|
34
34
|
|
35
35
|
ここで質問させていただきました
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
~補足~
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```C#
|
46
|
+
|
47
|
+
※Visual Studio 2015を使用しています
|
48
|
+
|
49
|
+
using UnityEngine;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
using System.Collections;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
public class NejikoController :
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
MonoBehaviour
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
const int MinLane = -2;
|
72
|
+
|
73
|
+
const int MaxLane = 2;
|
74
|
+
|
75
|
+
const float LaneWidth = 1.0f;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
CharacterController controller;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
Animator animator;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
Vector3 moveDirection = Vector3.zero;
|
96
|
+
|
97
|
+
int targetLane;
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
public float gravity;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
public float speedZ;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public float speedX;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
public float speedJump;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
public float accelerationZ;
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
// Use this for initialization
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
void Start()
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
controller = GetComponent<CharacterController>();
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
animator = GetComponent<Animator>();
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
// Update is called once per frame
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
void Update()
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
if (Input.GetKeyDown("left")) MoveToLeft();
|
172
|
+
|
173
|
+
if (Input.GetKeyDown("right")) MoveToRight();
|
174
|
+
|
175
|
+
if (Input.GetKeyDown("space")) Jump();
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
float acceleratiedZ = moveDirection.z + (accelerationZ * Time.deltaTime);
|
180
|
+
|
181
|
+
moveDirection.z = Mathf.Clamp(accelerationZ, 0, speedZ);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
float ratioX = (targetLane * LaneWidth - transform.position.x) / LaneWidth;
|
188
|
+
|
189
|
+
moveDirection.x = ratioX * speedX;
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
if (controller.isGrounded)
|
200
|
+
|
201
|
+
{
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
if (Input.GetAxis("Vertical") > 0.0f)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
moveDirection.z = Input.GetAxis("Vertical") * speedZ;
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
else
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
moveDirection.z = 0;
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
transform.Rotate(0, Input.GetAxis("Horizontal") * 3, 0);
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
if (Input.GetButton("Jump"))
|
254
|
+
|
255
|
+
{
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
moveDirection.y = speedJump;
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
animator.SetTrigger("jump");
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
moveDirection.y -= gravity * Time.deltaTime;
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
Vector3 globalDirection = transform.TransformDirection(moveDirection);
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
controller.Move(globalDirection * Time.deltaTime);
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
if (controller.isGrounded)
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
moveDirection.y = 0;
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
animator.SetBool("run", moveDirection.z > 0.0f);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
public void MoveToLeft()
|
332
|
+
|
333
|
+
{
|
334
|
+
|
335
|
+
if (controller.isGrounded && targetLane > MinLane) targetLane--;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
public void MoveToRight()
|
344
|
+
|
345
|
+
{
|
346
|
+
|
347
|
+
if (controller.isGrounded && targetLane > MaxLane) targetLane++;
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
public void Jump()
|
358
|
+
|
359
|
+
{
|
360
|
+
|
361
|
+
if (controller.isGrounded)
|
362
|
+
|
363
|
+
{
|
364
|
+
|
365
|
+
moveDirection.y = speedJump;
|
366
|
+
|
367
|
+
animator.SetTrigger("jump");
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
```
|
1
バージョンの詳細を書き忘れたので加えました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Unity5.5.4(パーソナル版)でC#スクリプトを作成したいのですが
|
1
|
+
Windows版Unity5.5.4(パーソナル版,64bit)でC#スクリプトを作成したいのですが
|
2
2
|
|
3
3
|
どんなC#スクリプトでも作成した時点で
|
4
4
|
|