質問編集履歴
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,8 +50,6 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
|
54
|
-
|
55
53
|
// Start is called before the first frame update
|
56
54
|
|
57
55
|
void Update()
|
@@ -82,11 +80,7 @@
|
|
82
80
|
|
83
81
|
}
|
84
82
|
|
85
|
-
}
|
83
|
+
}
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
84
|
|
91
85
|
}
|
92
86
|
|
@@ -160,10 +154,6 @@
|
|
160
154
|
|
161
155
|
|
162
156
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
157
|
// Update is called once per frame
|
168
158
|
|
169
159
|
void Update()
|
@@ -210,10 +200,6 @@
|
|
210
200
|
|
211
201
|
|
212
202
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
203
|
void Camera_Move()//視点操作&視点可動域制限
|
218
204
|
|
219
205
|
{
|
@@ -240,10 +226,6 @@
|
|
240
226
|
|
241
227
|
|
242
228
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
229
|
void Camera_Move_wall()//視点操作&視点可動域制限
|
248
230
|
|
249
231
|
{
|
@@ -274,10 +256,6 @@
|
|
274
256
|
|
275
257
|
|
276
258
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
259
|
void Player_Move()//プレイヤー移動操作
|
282
260
|
|
283
261
|
{
|
@@ -634,7 +612,7 @@
|
|
634
612
|
|
635
613
|
{
|
636
614
|
|
637
|
-
|
615
|
+
//未実装
|
638
616
|
|
639
617
|
}
|
640
618
|
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,122 +4,664 @@
|
|
4
4
|
|
5
5
|
用途としては壁走りを行う際、前方向にRayを飛ばし、あたったオブジェクトの中心点から右に離れているか左に離れているかを検出して、右なら右側に走るなどそんな感じに使う予定です。
|
6
6
|
|
7
|
+
|
8
|
+
|
7
|
-
###
|
9
|
+
### 該当のソースコード
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```ここに言語名を入力
|
14
|
+
|
15
|
+
ソースコードc#
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
using System.Collections;
|
20
|
+
|
21
|
+
using System.Collections.Generic;
|
22
|
+
|
23
|
+
using UnityEngine;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
public class In_flont : MonoBehaviour//前方方向にRayを飛ばしあたったオブジェクトの中心から左か右かを取得するスプリクト
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
[SerializeField] private player player;//壁走りの処理やその他もろもろを行うスクリプト
|
32
|
+
|
33
|
+
[SerializeField] private Ground Ground;//地面との当たり判定
|
34
|
+
|
35
|
+
[SerializeField] private Wall_Right Wall_Right;//壁との当たり判定(右)
|
36
|
+
|
37
|
+
[SerializeField] private wall_left Wall_left;//壁との当たり判定(左)
|
38
|
+
|
39
|
+
private float maxDistance = 0.9f;//Ray 長さ
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
void Start()
|
44
|
+
|
45
|
+
{
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// Start is called before the first frame update
|
56
|
+
|
57
|
+
void Update()
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
Ray ray = new Ray(transform.position, transform.forward);
|
62
|
+
|
63
|
+
RaycastHit hit;
|
64
|
+
|
65
|
+
Debug.DrawRay(ray.origin, ray.direction * maxDistance, Color.red);
|
66
|
+
|
67
|
+
if (Physics.Raycast(ray, out hit, maxDistance))
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
if (hit.collider.gameObject.tag == "wall" && !Ground.ground && player.moveSpeed == 10)
|
72
|
+
|
73
|
+
//壁を検出した時 && 地面に接触してない && 走る速さがその時10(MAX)なら
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
//たとえです
|
78
|
+
|
79
|
+
if(中心から角度が右なら){ Wall_left.Left_Walls = true;//左に壁走り}
|
80
|
+
|
81
|
+
else{Wall_Right.Right_Walls = true;//右に壁走り}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
8
94
|
|
9
95
|
|
10
96
|
|
11
97
|
```
|
12
98
|
|
99
|
+
```ここに言語を入力
|
100
|
+
|
101
|
+
using System;
|
102
|
+
|
103
|
+
using System.Collections;
|
104
|
+
|
105
|
+
using System.Collections.Generic;
|
106
|
+
|
107
|
+
using UnityEngine;
|
108
|
+
|
109
|
+
|
110
|
+
|
13
|
-
|
111
|
+
public class player : MonoBehaviour
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
[SerializeField] private Wall_Right Wall_Right;//壁との当たり判定(右)
|
116
|
+
|
117
|
+
[SerializeField] private wall_left Wall_left;//壁との当たり判定(左)
|
118
|
+
|
119
|
+
[SerializeField] private Ground Ground;//地面との衝突判定
|
120
|
+
|
121
|
+
private Player_Audio Audio;//プレイヤー音響
|
122
|
+
|
123
|
+
public Vector3 velocity;// 移動方向
|
124
|
+
|
125
|
+
private Vector3 Jump;//ジャンプ代入
|
126
|
+
|
127
|
+
public float moveSpeed;// 移動速度
|
128
|
+
|
129
|
+
private float walk_time;//歩いた時間
|
130
|
+
|
131
|
+
public Transform Rot;//Transform
|
132
|
+
|
133
|
+
private Rigidbody rd;//Rigidbody
|
134
|
+
|
135
|
+
private Vector3 roteto;//カメラ操作
|
136
|
+
|
137
|
+
private bool Landing;
|
138
|
+
|
139
|
+
public bool ok , Gravitystop; //補助コード
|
140
|
+
|
141
|
+
private float cameraZ; //壁走り時のカメラを斜めにする動作
|
142
|
+
|
143
|
+
// Use this for initialization
|
144
|
+
|
145
|
+
void Start()
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
rd = GetComponent<Rigidbody>();
|
150
|
+
|
151
|
+
Cursor.visible = false;
|
152
|
+
|
153
|
+
Cursor.lockState = CursorLockMode.Locked;
|
154
|
+
|
155
|
+
Audio = GetComponent<Player_Audio>();
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
// Update is called once per frame
|
168
|
+
|
169
|
+
void Update()
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
if (Wall_left.Left_Walls || Wall_Right.Right_Walls) { ok = true; } else { ok = false;Gravitystop = true; }
|
174
|
+
|
175
|
+
if (!ok)
|
176
|
+
|
177
|
+
{
|
178
|
+
|
179
|
+
Camera_Move();
|
180
|
+
|
181
|
+
Player_Move();
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
if (Wall_Right.Right_Walls)
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
cameraZ = 15;
|
190
|
+
|
191
|
+
Camera_Move_wall();
|
192
|
+
|
193
|
+
Rightwalk();
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
if (Wall_left.Left_Walls)
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
cameraZ = -15;
|
202
|
+
|
203
|
+
Camera_Move_wall();
|
204
|
+
|
205
|
+
Leftwalk();
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
void Camera_Move()//視点操作&視点可動域制限
|
218
|
+
|
219
|
+
{
|
220
|
+
|
221
|
+
float X_Rotation = Input.GetAxis("Mouse X");
|
222
|
+
|
223
|
+
float Y_Rotation = Input.GetAxis("Mouse Y");
|
224
|
+
|
225
|
+
Rot.transform.Rotate(-Y_Rotation, X_Rotation, 0);
|
226
|
+
|
227
|
+
Vector3 Y = Rot.transform.localEulerAngles;
|
228
|
+
|
229
|
+
if (Y.x >= 180)
|
230
|
+
|
231
|
+
Y.x -= 360;
|
232
|
+
|
233
|
+
Rot.transform.localEulerAngles = new Vector3(Mathf.Clamp(Y.x, -50, 55), 0, 0);
|
234
|
+
|
235
|
+
roteto = new Vector3(0, X_Rotation * 2, 0);
|
236
|
+
|
237
|
+
rd.transform.eulerAngles += roteto;
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
void Camera_Move_wall()//視点操作&視点可動域制限
|
248
|
+
|
249
|
+
{
|
250
|
+
|
251
|
+
float X_Rotation = Input.GetAxis("Mouse X");
|
252
|
+
|
253
|
+
float Y_Rotation = Input.GetAxis("Mouse Y");
|
254
|
+
|
255
|
+
Rot.transform.Rotate(-Y_Rotation, X_Rotation, 0);
|
256
|
+
|
257
|
+
Vector3 Y = Rot.transform.localEulerAngles;
|
258
|
+
|
259
|
+
if (Y.x >= 180)
|
260
|
+
|
261
|
+
Y.x -= 360;
|
262
|
+
|
263
|
+
if (Y.y >= 180)
|
264
|
+
|
265
|
+
Y.y -= 360;
|
266
|
+
|
267
|
+
Rot.transform.localEulerAngles = new Vector3(Mathf.Clamp(Y.x, -15, 15), Mathf.Clamp(Y.y, -15, 15), cameraZ);
|
268
|
+
|
269
|
+
roteto = new Vector3(0, X_Rotation * 2, 0);
|
270
|
+
|
271
|
+
Rot.transform.eulerAngles += roteto;
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
void Player_Move()//プレイヤー移動操作
|
282
|
+
|
283
|
+
{
|
284
|
+
|
285
|
+
//重力
|
286
|
+
|
287
|
+
if (!Ground.ground)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
Jump = Vector3.zero;
|
292
|
+
|
293
|
+
Jump.y -= 10 * Time.deltaTime;
|
294
|
+
|
295
|
+
rd.velocity += Jump;
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
//移動
|
300
|
+
|
301
|
+
velocity = Vector3.zero;
|
302
|
+
|
303
|
+
if (Input.GetKey(KeyCode.W))
|
304
|
+
|
305
|
+
velocity.z += 1;
|
306
|
+
|
307
|
+
if (Input.GetKey(KeyCode.A))
|
308
|
+
|
309
|
+
velocity.x -= 1;
|
310
|
+
|
311
|
+
if (Input.GetKey(KeyCode.S))
|
312
|
+
|
313
|
+
velocity.z -= 1;
|
314
|
+
|
315
|
+
if (Input.GetKey(KeyCode.D))
|
316
|
+
|
317
|
+
velocity.x += 1;
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
velocity = gameObject.transform.rotation * velocity.normalized * moveSpeed * Time.deltaTime;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
if (velocity.magnitude > 0) //動いたら...
|
328
|
+
|
329
|
+
{
|
330
|
+
|
331
|
+
transform.position += velocity; //移動操作をプレイヤーに代入
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
//走り
|
336
|
+
|
337
|
+
if (Input.GetKey(KeyCode.LeftShift) && moveSpeed <= 10 && Ground.ground)
|
338
|
+
|
339
|
+
{
|
340
|
+
|
341
|
+
moveSpeed += Time.deltaTime * 6;
|
342
|
+
|
343
|
+
if (moveSpeed > 10) moveSpeed = 10;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
if (!Input.GetKey(KeyCode.LeftShift) && moveSpeed >= 5)
|
348
|
+
|
349
|
+
{
|
350
|
+
|
351
|
+
moveSpeed -= 5 * Time.deltaTime * 6;
|
352
|
+
|
353
|
+
if (moveSpeed < 5) moveSpeed = 5;
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
if (Input.GetKeyDown(KeyCode.Space) || !Ground.ground)//spaceキー押してないなら
|
358
|
+
|
359
|
+
walk_time = 0;
|
360
|
+
|
361
|
+
if (!Ground.ground && moveSpeed < 0)//壁走り解除後のスピード補正
|
362
|
+
|
363
|
+
moveSpeed = 5;
|
364
|
+
|
365
|
+
else
|
366
|
+
|
367
|
+
{
|
368
|
+
|
369
|
+
//歩いている時間を計測(走ると倍)
|
370
|
+
|
371
|
+
walk_time += Time.deltaTime * moveSpeed / 7;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
else
|
380
|
+
|
381
|
+
{
|
382
|
+
|
383
|
+
moveSpeed = 5;
|
384
|
+
|
385
|
+
walk_time = 0;
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
//ジャンプ
|
390
|
+
|
391
|
+
Jump = Vector3.zero;
|
392
|
+
|
393
|
+
if (Input.GetKeyDown(KeyCode.Space) && Ground.ground)
|
394
|
+
|
395
|
+
{
|
396
|
+
|
397
|
+
Jump.y += 5;
|
398
|
+
|
399
|
+
Audio.Player_Sound_janp();
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
if (Ground.ground)
|
404
|
+
|
405
|
+
{
|
406
|
+
|
407
|
+
if (Landing)
|
408
|
+
|
409
|
+
{
|
410
|
+
|
411
|
+
Audio.Player_Sound_Landing();
|
412
|
+
|
413
|
+
Landing = false;
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
else
|
422
|
+
|
423
|
+
{
|
424
|
+
|
425
|
+
Landing = true;
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
if (Jump.magnitude > 0)
|
434
|
+
|
435
|
+
{
|
436
|
+
|
437
|
+
rd.velocity += Jump;
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
if (walk_time > 0.5)//歩行時間が一定を超えたら
|
444
|
+
|
445
|
+
{
|
446
|
+
|
447
|
+
walk_time = 0;
|
448
|
+
|
449
|
+
Audio.Player_Sound();
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
void Leftwalk()
|
462
|
+
|
463
|
+
{
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
////////////////////////////初期設定(一度のみ)//////////////////////////////////
|
468
|
+
|
469
|
+
if (Gravitystop)
|
470
|
+
|
471
|
+
{
|
472
|
+
|
473
|
+
Rot.transform.Rotate(new Vector3(0, 0, -15));
|
474
|
+
|
475
|
+
transform.rotation = Quaternion.AngleAxis(Wall_left.Wall_angle, new Vector3(0, 1, 0));
|
476
|
+
|
477
|
+
rd.isKinematic = true;
|
478
|
+
|
479
|
+
Gravitystop = false;
|
480
|
+
|
481
|
+
rd.isKinematic = false;
|
482
|
+
|
483
|
+
}
|
484
|
+
|
485
|
+
////////////////////////////初期設定(一度のみ)//////////////////////////////////
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
if (Input.GetKey(KeyCode.Space) && moveSpeed < 8)//space押されてないなら
|
494
|
+
|
495
|
+
{ }
|
496
|
+
|
497
|
+
else {
|
498
|
+
|
499
|
+
///////////////////////////プレイヤーの動き/////////////////////////////////////
|
500
|
+
|
501
|
+
velocity = Vector3.zero;
|
502
|
+
|
503
|
+
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
|
504
|
+
|
505
|
+
{
|
506
|
+
|
507
|
+
velocity.z += 1;
|
508
|
+
|
509
|
+
moveSpeed -= Time.deltaTime * 3;
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
}
|
514
|
+
|
515
|
+
else
|
516
|
+
|
517
|
+
{
|
518
|
+
|
519
|
+
moveSpeed = 0;
|
520
|
+
|
521
|
+
}
|
522
|
+
|
523
|
+
if (Input.GetKey(KeyCode.D))
|
524
|
+
|
525
|
+
velocity.x += 1;
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
velocity = gameObject.transform.rotation * velocity.normalized * 10 * Time.deltaTime;
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
if (velocity.magnitude > 0) //動いたら...
|
534
|
+
|
535
|
+
{
|
536
|
+
|
537
|
+
transform.position += velocity; //移動操作をプレイヤーに代入
|
538
|
+
|
539
|
+
}
|
540
|
+
|
541
|
+
///////////////////////////プレイヤーの動き/////////////////////////////////////
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
///////////////////////////走るサウンド/////////////////////////////////////////
|
546
|
+
|
547
|
+
walk_time += Time.deltaTime * 2;
|
548
|
+
|
549
|
+
if (walk_time > 0.5)//歩行時間が一定を超えたら
|
550
|
+
|
551
|
+
{
|
552
|
+
|
553
|
+
walk_time = 0;
|
554
|
+
|
555
|
+
Audio.Player_Sound();
|
556
|
+
|
557
|
+
}
|
558
|
+
|
559
|
+
///////////////////////////走るサウンド/////////////////////////////////////////
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
///////////////////////////壁走りの上昇&下降///////////////////////////////////
|
564
|
+
|
565
|
+
Jump = Vector3.zero;
|
566
|
+
|
567
|
+
if (moveSpeed > 5)
|
568
|
+
|
569
|
+
{
|
570
|
+
|
571
|
+
Jump.y += 1;
|
572
|
+
|
573
|
+
Jump = gameObject.transform.rotation * Jump.normalized * Time.deltaTime * moveSpeed / 4;
|
574
|
+
|
575
|
+
}
|
576
|
+
|
577
|
+
if (moveSpeed < 5 && moveSpeed > 4)
|
578
|
+
|
579
|
+
{
|
580
|
+
|
581
|
+
Jump.y += 1;
|
582
|
+
|
583
|
+
Jump = gameObject.transform.rotation * Jump.normalized * Time.deltaTime;
|
584
|
+
|
585
|
+
}
|
586
|
+
|
587
|
+
if (moveSpeed < 4 && moveSpeed > 3)
|
588
|
+
|
589
|
+
{
|
590
|
+
|
591
|
+
Jump.y -= 1;
|
592
|
+
|
593
|
+
Jump = gameObject.transform.rotation * Jump.normalized * Time.deltaTime / 2;
|
594
|
+
|
595
|
+
}
|
596
|
+
|
597
|
+
if (moveSpeed < 3 && moveSpeed > 2)
|
598
|
+
|
599
|
+
{
|
600
|
+
|
601
|
+
Jump.y -= 1;
|
602
|
+
|
603
|
+
Jump = gameObject.transform.rotation * Jump.normalized * Time.deltaTime;
|
604
|
+
|
605
|
+
}
|
606
|
+
|
607
|
+
if (moveSpeed < 2)
|
608
|
+
|
609
|
+
{
|
610
|
+
|
611
|
+
Jump.y -= 1;
|
612
|
+
|
613
|
+
Jump = gameObject.transform.rotation * Jump.normalized * Time.deltaTime * 2;
|
614
|
+
|
615
|
+
}
|
616
|
+
|
617
|
+
if (Jump.magnitude > 0) //動いたら...
|
618
|
+
|
619
|
+
{
|
620
|
+
|
621
|
+
transform.position += Jump; //移動操作をプレイヤーに代入
|
622
|
+
|
623
|
+
}
|
624
|
+
|
625
|
+
///////////////////////////壁走りの上昇&下降///////////////////////////////////
|
626
|
+
|
627
|
+
}
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
///////////////////////////ジャンプ処理/////////////////////////////////////////////
|
632
|
+
|
633
|
+
if (Input.GetKeyDown(KeyCode.Space))
|
634
|
+
|
635
|
+
{
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
}
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
///////////////////////////ジャンプ処理/////////////////////////////////////////////
|
644
|
+
|
645
|
+
if(moveSpeed < 0)
|
646
|
+
|
647
|
+
{
|
648
|
+
|
649
|
+
moveSpeed = 0;
|
650
|
+
|
651
|
+
}
|
652
|
+
|
653
|
+
}
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
void Rightwalk()
|
658
|
+
|
659
|
+
{
|
660
|
+
|
661
|
+
//省略
|
662
|
+
|
663
|
+
}
|
664
|
+
|
665
|
+
}
|
14
666
|
|
15
667
|
```
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
### 該当のソースコード
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
```ここに言語名を入力
|
24
|
-
|
25
|
-
ソースコードc#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
using System.Collections;
|
30
|
-
|
31
|
-
using System.Collections.Generic;
|
32
|
-
|
33
|
-
using UnityEngine;
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
public class In_flont : MonoBehaviour//前方方向にRayを飛ばしあたったオブジェクトの中心から左か右かを取得するスプリクト
|
38
|
-
|
39
|
-
{
|
40
|
-
|
41
|
-
[SerializeField] private player player;//壁走りの処理やその他もろもろを行うスクリプト
|
42
|
-
|
43
|
-
[SerializeField] private Ground Ground;//地面との当たり判定
|
44
|
-
|
45
|
-
[SerializeField] private Wall_Right Wall_Right;//壁との当たり判定(右)
|
46
|
-
|
47
|
-
[SerializeField] private wall_left Wall_left;//壁との当たり判定(左)
|
48
|
-
|
49
|
-
private float maxDistance = 0.9f;//Ray 長さ
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
void Start()
|
54
|
-
|
55
|
-
{
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
// Start is called before the first frame update
|
66
|
-
|
67
|
-
void Update()
|
68
|
-
|
69
|
-
{
|
70
|
-
|
71
|
-
Ray ray = new Ray(transform.position, transform.forward);
|
72
|
-
|
73
|
-
RaycastHit hit;
|
74
|
-
|
75
|
-
Debug.DrawRay(ray.origin, ray.direction * maxDistance, Color.red);
|
76
|
-
|
77
|
-
if (Physics.Raycast(ray, out hit, maxDistance))
|
78
|
-
|
79
|
-
{
|
80
|
-
|
81
|
-
if (hit.collider.gameObject.tag == "wall" && !Ground.ground && player.moveSpeed == 10)
|
82
|
-
|
83
|
-
//壁を検出した時 && 地面に接触してない && 走る速さがその時10(MAX)なら
|
84
|
-
|
85
|
-
{
|
86
|
-
|
87
|
-
//たとえです
|
88
|
-
|
89
|
-
if(中心から角度が右なら){ Wall_left.Left_Walls = true;//左に壁走り}
|
90
|
-
|
91
|
-
else{Wall_Right.Right_Walls = true;//右に壁走り}
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
```
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
### 試したこと
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
オブジェクトの中心からの角度を引き出し左右の検出コードの書き方がわからず、とまっている状況です。
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
### 補足情報(FW/ツールのバージョンなど)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
用途としては壁走りを行う際、前方向にRayを飛ばし、あたったオブジェクトの中心点から右に離れているか左に離れているかを検出して、右なら右側に走るなどそんな感じに使う予定です。
|
124
|
-
|
125
|
-
プログラミングを始めて1か月たたないほどなので、やり方としてきたなかったり、醜かったりしてしまいますが、どうぞよろしくお願いいたします。
|