質問編集履歴

9

a

2020/04/20 15:11

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -96,10 +96,20 @@
96
96
 
97
97
  }
98
98
 
99
+
100
+
101
+ ```
102
+
103
+
104
+
99
105
  OniController
100
106
 
107
+
108
+
101
109
  ```C#
102
110
 
111
+
112
+
103
113
  using System.Collections;
104
114
 
105
115
  using System.Collections.Generic;
@@ -264,4 +274,6 @@
264
274
 
265
275
 
266
276
 
277
+
278
+
267
279
  ```

8

miss

2020/04/20 15:10

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -262,4 +262,6 @@
262
262
 
263
263
 
264
264
 
265
+
266
+
265
267
  ```

7

スクリプトの追加

2020/04/20 15:09

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
@@ -1 +1 @@
1
- unity3D 捕まったレイヤー待機場所実装
1
+ unity3D スクリboolが全て複数オブジェクトに反映されてしまう。
test CHANGED
@@ -1,30 +1,26 @@
1
- unity3Dで鬼ごっこゲームを作ます。
1
+ unity3d鬼ごっこゲームを作成しおります。
2
-
3
-
4
-
5
- プレイヤーと鬼を選んで遊べるゲームです。
2
+
6
-
7
-
8
-
9
- プレイヤーを操作する際、鬼に捕まった場合は指定した座標にtransform.positionで送るように設定をしており、その四方に空のオブジェクトを生成し、ボックスコライダーで壁を作ることで牢屋を生成し、プレイヤーの動きをその範囲内でしか行動できないようにしており、
3
+
10
-
11
- 他のプレイヤーが助けにきた際に施錠できるようにするために牢屋の外側の四方に空のオブジェクトを作成しているのですが、鬼を操作した際にその牢屋の四方の内部が移動できない状態になってしまいます。(円とライトで牢屋を作成しているのでその中も動けるようにしたいと考えております。)
4
+
12
-
13
-
14
-
15
- 解決方法として1つの大きなボックスコライダーをアタッチし、OncolisionStayでの実装をしようとしましたが、
16
-
17
- 他のプレイヤーがその範囲に入った時のみ解錠できるようにいのでオブジェクトにボックスコラーを一つアタッチし範囲を設定した際にプレイヤーが内部から解錠できてしまうので、実装方法悩んでおります。
5
+ プレイヤーと鬼を2対ずつ用意をのですが、鬼が1対プレーを捕まえた際にプレイヤーが二体と捕まってしまうようなってしいます。
6
+
18
-
7
+ プレイヤーごとにboolの判定を分けたい場合どのようにすれば良いかアドバイスをいただけますと幸いです。
8
+
9
+
10
+
11
+
12
+
19
-
13
+ 下記にスクリプトを追加させていただきました。
20
-
14
+
21
- プレイヤーにはPlayerタグ、鬼にはoniタグつけ判定を行なっております。
15
+ PlayerController,OniControllerでの実装ております。
16
+
22
-
17
+ 鬼がプレイヤーに近付いたらそのプレイヤーが捕獲されるにしたいと考えております。(実際は他のプレイヤーも所定の場所に飛ばされてしまいます。)
23
-
24
-
18
+
19
+
20
+
21
+
22
+
25
- どなたかアドバイスをいただけますと幸いです。
23
+ PlayerScripts
26
-
27
-
28
24
 
29
25
  ```C#
30
26
 
@@ -34,31 +30,109 @@
34
30
 
35
31
  using UnityEngine;
36
32
 
37
-
33
+ using UnityEngine.UI;
38
-
34
+
35
+
36
+
39
- public class GameController : MonoBehaviour
37
+ public class PlayerController : MonoBehaviour
40
38
 
41
39
  {
42
40
 
41
+ [SerializeField] public OniController anotherScript1;
42
+
43
+
44
+
45
+    void Start()
46
+
47
+ {
48
+
49
+
50
+
51
+
52
+
53
+ anotherScript = GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter>();
54
+
55
+
56
+
57
+ GameObject anotherObject = GameObject.FindWithTag("Oni");
58
+
59
+ anotherScript1 = anotherObject.GetComponent<OniController>();
60
+
61
+
62
+
63
+
64
+
65
+ }
66
+
67
+
68
+
69
+ void Update()
70
+
71
+ {
72
+
73
+ if (anotherScript1.isRouya == true)
74
+
75
+ {
76
+
77
+ float rouya_y = 1.5f;
78
+
79
+
80
+
81
+ transform.position = new Vector3(65, rouya_y, 65);
82
+
83
+
84
+
85
+ }
86
+
87
+ }
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+ }
98
+
99
+ OniController
100
+
101
+ ```C#
102
+
103
+ using System.Collections;
104
+
105
+ using System.Collections.Generic;
106
+
107
+ using UnityEngine;
108
+
109
+ using UnityEngine.UI;
110
+
111
+
112
+
43
- public GameObject ButtonKaiho;
113
+ public class OniController : MonoBehaviour
44
-
114
+
45
- public GameObject Rouya;
115
+ {
46
116
 
47
117
  //プレイヤーの取得
48
118
 
49
- GameObject Player;
50
-
51
-
52
-
53
- //スクリプトの取得
54
-
55
- public PlayerController PlayerControllerScript;
119
+ List<GameObject> Players = new List<GameObject>();
56
-
120
+
121
+
122
+
57
- public RouyaScript RouyaScript;
123
+ public bool isRouya;
124
+
125
+
126
+
127
+
128
+
129
+
130
+
58
-
131
+ [SerializeField] private Oni.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript;
59
-
60
-
61
-
132
+
133
+
134
+
135
+
62
136
 
63
137
 
64
138
 
@@ -68,526 +142,124 @@
68
142
 
69
143
  //プレイヤーの取得
70
144
 
71
- this.Player = GameObject.Find("Player");
145
+ Players.AddRange(GameObject.FindGameObjectsWithTag("Player"));
146
+
147
+
148
+
72
-
149
+ anotherScript = GetComponent<Oni.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter>();
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
73
- }
159
+ }
74
-
75
-
76
-
160
+
161
+
162
+
163
+
164
+
77
- void Update()
165
+ public void OnCollisionStay(Collision hit)
78
-
166
+
79
- {
167
+ {
80
-
81
-
82
-
168
+
83
- //他のプレイヤーのロック解放
169
+ // 接触対象はPlayerタグですか?
84
-
170
+
85
- if (Rouya.GetComponent<RouyaScript>().ishelp == true)
171
+ if (hit.gameObject.tag == "Player")
86
172
 
87
173
  {
88
174
 
175
+ //Debug.Log("プレイヤーと接触している");
176
+
177
+
178
+
89
- ButtonKaiho.SetActive(true);
179
+ OnButtonHokaku();
90
180
 
91
181
 
92
182
 
93
183
  }
94
184
 
185
+
186
+
95
- else
187
+ }
188
+
189
+
190
+
96
-
191
+ public void OnButtonHokaku()
192
+
97
- {
193
+ {
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
98
-
203
+ Invoke("Rouya", 0.7f);
204
+
99
- ButtonKaiho.SetActive(false);
205
+ anotherScript.TouchStart();
206
+
100
-
207
+ Invoke("OnTouchEnd", 0.5f);
101
-
102
-
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
103
- }
223
+ }
224
+
104
-
225
+ public void Rouya()
226
+
227
+ {
228
+
229
+
230
+
231
+
232
+
233
+ isRouya = true;
234
+
235
+
236
+
237
+
238
+
239
+
240
+
105
- }
241
+ }
242
+
106
-
243
+ //アニメーションです。
107
-
108
-
244
+
109
- public void OnButtonKaiho()
245
+ public void OnTouchEnd()
110
-
246
+
111
- {
247
+ {
112
-
248
+
113
- Rouya.SetActive(false);
249
+ anotherScript.TouchEnd();
114
-
115
- Debug.Log("牢屋消えた");
250
+
116
-
117
-
118
-
119
- Player.GetComponent<OniController>().isCaptured = false;
120
-
121
- Debug.Log("プレイヤー捕まってない状態");
122
-
123
- Rouya.GetComponent<RouyaScript>().ishelp = false;
124
-
125
- Debug.Log("助ける状態のリセット");
126
-
127
- }
251
+ }
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
128
260
 
129
261
  }
130
262
 
131
263
 
132
264
 
133
265
  ```
134
-
135
- ```C#
136
-
137
- using System.Collections;
138
-
139
- using System.Collections.Generic;
140
-
141
- using UnityEngine;
142
-
143
-
144
-
145
- public class RouyaScript : MonoBehaviour
146
-
147
- {
148
-
149
- //プレイヤーの取得
150
-
151
- GameObject Player;
152
-
153
- public bool ishelp;
154
-
155
-
156
-
157
-
158
-
159
- // Start is called before the first frame update
160
-
161
- void Start()
162
-
163
- {
164
-
165
-      //プレイヤーの取得
166
-
167
- this.Player = GameObject.Find("Player");
168
-
169
-
170
-
171
- }
172
-
173
-
174
-
175
-
176
-
177
- //牢屋にプレイヤーが触れた場合
178
-
179
- public void OnCollisionEnter(Collision hit)
180
-
181
- {
182
-
183
- if (hit.gameObject.tag == "Player")
184
-
185
-
186
-
187
- if (Player.GetComponent<PlayerController>().isCaptured == false)
188
-
189
- {
190
-
191
-
192
-
193
-
194
-
195
- Help();
196
-
197
-
198
-
199
- }
200
-
201
- }
202
-
203
-
204
-
205
- void Help()
206
-
207
- {
208
-
209
- ishelp = true;
210
-
211
-
212
-
213
- }
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
- }
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
- ```
230
-
231
- ```C#
232
-
233
- using System.Collections;
234
-
235
- using System.Collections.Generic;
236
-
237
- using UnityEngine;
238
-
239
- using UnityEngine.UI;
240
-
241
-
242
-
243
- public class PlayerController : MonoBehaviour
244
-
245
- {
246
-
247
- //プレイヤーにアタッチされている足の速さを決めるスクリプト
248
-
249
- [SerializeField] private UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter anotherScript;
250
-
251
-
252
-
253
- void Start()
254
-
255
- {
256
-
257
-
258
-
259
-
260
-
261
- anotherScript = GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter>();
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
- }
270
-
271
-
272
-
273
- void Update()
274
-
275
- {
276
-
277
- if (isCaptured == true)
278
-
279
- {
280
-
281
- //捕まっている場合は0
282
-
283
- SetValue(0);
284
-
285
- }
286
-
287
-
288
-
289
- if (isCaptured == false)
290
-
291
- {
292
-
293
- SetValue(2);
294
-
295
- }
296
-
297
-
298
-
299
- }
300
-
301
-
302
-
303
-
304
-
305
- public void OnTriggerStay(Collider hit)
306
-
307
- {
308
-
309
- // 牢屋に触れた場合
310
-
311
-
312
-
313
- if (hit.gameObject.tag == "Rouya")
314
-
315
- {
316
-
317
-
318
-
319
- Captured();
320
-
321
-
322
-
323
- }
324
-
325
-
326
-
327
-
328
-
329
- }
330
-
331
-
332
-
333
-
334
-
335
- void SetValue(int value)
336
-
337
- {
338
-
339
- anotherScript.M_MoveSpeedMultiplier = value;
340
-
341
-
342
-
343
- //Debug.Log("M_MoveSpeedMultiplie = " + anotherScript.M_MoveSpeedMultiplier);
344
-
345
- }
346
-
347
-
348
-
349
- public void Captured()
350
-
351
- {
352
-
353
- isCaptured = true;
354
-
355
- }
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
- }
368
-
369
-
370
-
371
-
372
-
373
- ```
374
-
375
- 鬼のスクリプトのみ抜粋いたしました。
376
-
377
- ```C#
378
-
379
- using System.Collections;
380
-
381
- using System.Collections.Generic;
382
-
383
- using UnityEngine;
384
-
385
- using UnityEngine.UI;
386
-
387
-
388
-
389
- public class GameController : MonoBehaviour
390
-
391
- {
392
-
393
- List<GameObject> Oni = new List<GameObject>();
394
-
395
-
396
-
397
-
398
-
399
- void Start()
400
-
401
- {
402
-
403
-
404
-
405
-
406
-
407
- Onis.AddRange(GameObject.FindGameObjectsWithTag("Oni"));
408
-
409
-
410
-
411
-
412
-
413
- }
414
-
415
-
416
-
417
-
418
-
419
- void Update()
420
-
421
- {
422
-
423
- foreach (GameObject oni in Onis)
424
-
425
- {
426
-
427
- //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisHokakuの部分にエラーが出て不可能でした。
428
-
429
- if (oni.GetComponents<PoliceController>().isHokaku == true)
430
-
431
- {
432
-
433
- Rouya.SetActive(true);
434
-
435
-
436
-
437
- }
438
-
439
- else
440
-
441
- {
442
-
443
- Rouya.SetActive(false);
444
-
445
-
446
-
447
- }
448
-
449
-
450
-
451
- }
452
-
453
- }
454
-
455
-
456
-
457
-
458
-
459
- ```
460
-
461
-
462
-
463
- ```C#
464
-
465
- using System.Collections;
466
-
467
- using System.Collections.Generic;
468
-
469
- using UnityEngine;
470
-
471
- using UnityEngine.UI;
472
-
473
-
474
-
475
- public class OniController : MonoBehaviour
476
-
477
- {
478
-
479
- GameObject Player;
480
-
481
- public bool isHokaku;
482
-
483
-
484
-
485
- [SerializeField] private Police.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript;
486
-
487
-
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
- void Start()
496
-
497
- {
498
-
499
- this.Player = GameObject.Find("Player");
500
-
501
- anotherScript = GetComponent<Police.UnityStandardAssets.Characters.ThirdPerson.Police_ThirdPersonCharacter>();
502
-
503
-
504
-
505
-
506
-
507
- }
508
-
509
-
510
-
511
-
512
-
513
- public void OnCollisionStay(Collision hit)
514
-
515
- {
516
-
517
- // 接触対象はPlayerタグですか?
518
-
519
- if (hit.gameObject.tag == "Player")
520
-
521
- {
522
-
523
- //Debug.Log("プレイヤーと接触している");
524
-
525
- OnButtonHokaku();
526
-
527
-
528
-
529
- }
530
-
531
-
532
-
533
- }
534
-
535
-
536
-
537
- public void OnButtonHokaku()
538
-
539
- {
540
-
541
-
542
-
543
-
544
-
545
- Invoke("Hokaku", 0.7f);
546
-
547
- anotherScript.TouchStart();
548
-
549
- Invoke("OnTouchEnd", 0.5f);
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
- }
560
-
561
- public void Hokaku()
562
-
563
- {
564
-
565
- isHokaku = true;
566
-
567
- float rouya_y = 1.5f;
568
-
569
- this.Player.transform.position = new Vector3(65, rouya_y, 65);
570
-
571
-
572
-
573
- }
574
-
575
-
576
-
577
- public void OnTouchEnd()
578
-
579
- {
580
-
581
- anotherScript.TouchEnd();
582
-
583
- }
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
- }
592
-
593
- ```

6

a

2020/04/20 15:04

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -116,7 +116,7 @@
116
116
 
117
117
 
118
118
 
119
- Player.GetComponent<PlayerController>().isCaptured = false;
119
+ Player.GetComponent<OniController>().isCaptured = false;
120
120
 
121
121
  Debug.Log("プレイヤー捕まってない状態");
122
122
 

5

a

2020/04/20 09:59

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -457,3 +457,137 @@
457
457
 
458
458
 
459
459
  ```
460
+
461
+
462
+
463
+ ```C#
464
+
465
+ using System.Collections;
466
+
467
+ using System.Collections.Generic;
468
+
469
+ using UnityEngine;
470
+
471
+ using UnityEngine.UI;
472
+
473
+
474
+
475
+ public class OniController : MonoBehaviour
476
+
477
+ {
478
+
479
+ GameObject Player;
480
+
481
+ public bool isHokaku;
482
+
483
+
484
+
485
+ [SerializeField] private Police.UnityStandardAssets.Characters.ThirdPerson.Oni_ThirdPersonCharacter anotherScript;
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+ void Start()
496
+
497
+ {
498
+
499
+ this.Player = GameObject.Find("Player");
500
+
501
+ anotherScript = GetComponent<Police.UnityStandardAssets.Characters.ThirdPerson.Police_ThirdPersonCharacter>();
502
+
503
+
504
+
505
+
506
+
507
+ }
508
+
509
+
510
+
511
+
512
+
513
+ public void OnCollisionStay(Collision hit)
514
+
515
+ {
516
+
517
+ // 接触対象はPlayerタグですか?
518
+
519
+ if (hit.gameObject.tag == "Player")
520
+
521
+ {
522
+
523
+ //Debug.Log("プレイヤーと接触している");
524
+
525
+ OnButtonHokaku();
526
+
527
+
528
+
529
+ }
530
+
531
+
532
+
533
+ }
534
+
535
+
536
+
537
+ public void OnButtonHokaku()
538
+
539
+ {
540
+
541
+
542
+
543
+
544
+
545
+ Invoke("Hokaku", 0.7f);
546
+
547
+ anotherScript.TouchStart();
548
+
549
+ Invoke("OnTouchEnd", 0.5f);
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+ }
560
+
561
+ public void Hokaku()
562
+
563
+ {
564
+
565
+ isHokaku = true;
566
+
567
+ float rouya_y = 1.5f;
568
+
569
+ this.Player.transform.position = new Vector3(65, rouya_y, 65);
570
+
571
+
572
+
573
+ }
574
+
575
+
576
+
577
+ public void OnTouchEnd()
578
+
579
+ {
580
+
581
+ anotherScript.TouchEnd();
582
+
583
+ }
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+ }
592
+
593
+ ```

4

a

2020/04/20 09:58

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -424,7 +424,7 @@
424
424
 
425
425
  {
426
426
 
427
- //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisTaihoの部分にエラーが出て不可能でした。
427
+ //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisHokakuの部分にエラーが出て不可能でした。
428
428
 
429
429
  if (oni.GetComponents<PoliceController>().isHokaku == true)
430
430
 

3

add

2020/04/20 09:52

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -371,3 +371,89 @@
371
371
 
372
372
 
373
373
  ```
374
+
375
+ 鬼のスクリプトのみ抜粋いたしました。
376
+
377
+ ```C#
378
+
379
+ using System.Collections;
380
+
381
+ using System.Collections.Generic;
382
+
383
+ using UnityEngine;
384
+
385
+ using UnityEngine.UI;
386
+
387
+
388
+
389
+ public class GameController : MonoBehaviour
390
+
391
+ {
392
+
393
+ List<GameObject> Oni = new List<GameObject>();
394
+
395
+
396
+
397
+
398
+
399
+ void Start()
400
+
401
+ {
402
+
403
+
404
+
405
+
406
+
407
+ Onis.AddRange(GameObject.FindGameObjectsWithTag("Oni"));
408
+
409
+
410
+
411
+
412
+
413
+ }
414
+
415
+
416
+
417
+
418
+
419
+ void Update()
420
+
421
+ {
422
+
423
+ foreach (GameObject oni in Onis)
424
+
425
+ {
426
+
427
+ //子要素の一つでもbool型のisHokakuがtureならば牢屋を出してあげたいのですがisTaihoの部分にエラーが出て不可能でした。
428
+
429
+ if (oni.GetComponents<PoliceController>().isHokaku == true)
430
+
431
+ {
432
+
433
+ Rouya.SetActive(true);
434
+
435
+
436
+
437
+ }
438
+
439
+ else
440
+
441
+ {
442
+
443
+ Rouya.SetActive(false);
444
+
445
+
446
+
447
+ }
448
+
449
+
450
+
451
+ }
452
+
453
+ }
454
+
455
+
456
+
457
+
458
+
459
+ ```

2

add

2020/04/20 01:54

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,351 @@
23
23
 
24
24
 
25
25
  どなたかアドバイスをいただけますと幸いです。
26
+
27
+
28
+
29
+ ```C#
30
+
31
+ using System.Collections;
32
+
33
+ using System.Collections.Generic;
34
+
35
+ using UnityEngine;
36
+
37
+
38
+
39
+ public class GameController : MonoBehaviour
40
+
41
+ {
42
+
43
+ public GameObject ButtonKaiho;
44
+
45
+ public GameObject Rouya;
46
+
47
+ //プレイヤーの取得
48
+
49
+ GameObject Player;
50
+
51
+
52
+
53
+ //スクリプトの取得
54
+
55
+ public PlayerController PlayerControllerScript;
56
+
57
+ public RouyaScript RouyaScript;
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+ void Start()
66
+
67
+ {
68
+
69
+ //プレイヤーの取得
70
+
71
+ this.Player = GameObject.Find("Player");
72
+
73
+ }
74
+
75
+
76
+
77
+ void Update()
78
+
79
+ {
80
+
81
+
82
+
83
+ //他のプレイヤーのロック解放
84
+
85
+ if (Rouya.GetComponent<RouyaScript>().ishelp == true)
86
+
87
+ {
88
+
89
+ ButtonKaiho.SetActive(true);
90
+
91
+
92
+
93
+ }
94
+
95
+ else
96
+
97
+ {
98
+
99
+ ButtonKaiho.SetActive(false);
100
+
101
+
102
+
103
+ }
104
+
105
+ }
106
+
107
+
108
+
109
+ public void OnButtonKaiho()
110
+
111
+ {
112
+
113
+ Rouya.SetActive(false);
114
+
115
+ Debug.Log("牢屋消えた");
116
+
117
+
118
+
119
+ Player.GetComponent<PlayerController>().isCaptured = false;
120
+
121
+ Debug.Log("プレイヤー捕まってない状態");
122
+
123
+ Rouya.GetComponent<RouyaScript>().ishelp = false;
124
+
125
+ Debug.Log("助ける状態のリセット");
126
+
127
+ }
128
+
129
+ }
130
+
131
+
132
+
133
+ ```
134
+
135
+ ```C#
136
+
137
+ using System.Collections;
138
+
139
+ using System.Collections.Generic;
140
+
141
+ using UnityEngine;
142
+
143
+
144
+
145
+ public class RouyaScript : MonoBehaviour
146
+
147
+ {
148
+
149
+ //プレイヤーの取得
150
+
151
+ GameObject Player;
152
+
153
+ public bool ishelp;
154
+
155
+
156
+
157
+
158
+
159
+ // Start is called before the first frame update
160
+
161
+ void Start()
162
+
163
+ {
164
+
165
+      //プレイヤーの取得
166
+
167
+ this.Player = GameObject.Find("Player");
168
+
169
+
170
+
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+ //牢屋にプレイヤーが触れた場合
178
+
179
+ public void OnCollisionEnter(Collision hit)
180
+
181
+ {
182
+
183
+ if (hit.gameObject.tag == "Player")
184
+
185
+
186
+
187
+ if (Player.GetComponent<PlayerController>().isCaptured == false)
188
+
189
+ {
190
+
191
+
192
+
193
+
194
+
195
+ Help();
196
+
197
+
198
+
199
+ }
200
+
201
+ }
202
+
203
+
204
+
205
+ void Help()
206
+
207
+ {
208
+
209
+ ishelp = true;
210
+
211
+
212
+
213
+ }
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ }
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+ ```
230
+
231
+ ```C#
232
+
233
+ using System.Collections;
234
+
235
+ using System.Collections.Generic;
236
+
237
+ using UnityEngine;
238
+
239
+ using UnityEngine.UI;
240
+
241
+
242
+
243
+ public class PlayerController : MonoBehaviour
244
+
245
+ {
246
+
247
+ //プレイヤーにアタッチされている足の速さを決めるスクリプト
248
+
249
+ [SerializeField] private UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter anotherScript;
250
+
251
+
252
+
253
+ void Start()
254
+
255
+ {
256
+
257
+
258
+
259
+
260
+
261
+ anotherScript = GetComponent<UnityStandardAssets.Characters.ThirdPerson.ThirdPersonCharacter>();
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+ }
270
+
271
+
272
+
273
+ void Update()
274
+
275
+ {
276
+
277
+ if (isCaptured == true)
278
+
279
+ {
280
+
281
+ //捕まっている場合は0
282
+
283
+ SetValue(0);
284
+
285
+ }
286
+
287
+
288
+
289
+ if (isCaptured == false)
290
+
291
+ {
292
+
293
+ SetValue(2);
294
+
295
+ }
296
+
297
+
298
+
299
+ }
300
+
301
+
302
+
303
+
304
+
305
+ public void OnTriggerStay(Collider hit)
306
+
307
+ {
308
+
309
+ // 牢屋に触れた場合
310
+
311
+
312
+
313
+ if (hit.gameObject.tag == "Rouya")
314
+
315
+ {
316
+
317
+
318
+
319
+ Captured();
320
+
321
+
322
+
323
+ }
324
+
325
+
326
+
327
+
328
+
329
+ }
330
+
331
+
332
+
333
+
334
+
335
+ void SetValue(int value)
336
+
337
+ {
338
+
339
+ anotherScript.M_MoveSpeedMultiplier = value;
340
+
341
+
342
+
343
+ //Debug.Log("M_MoveSpeedMultiplie = " + anotherScript.M_MoveSpeedMultiplier);
344
+
345
+ }
346
+
347
+
348
+
349
+ public void Captured()
350
+
351
+ {
352
+
353
+ isCaptured = true;
354
+
355
+ }
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+ }
368
+
369
+
370
+
371
+
372
+
373
+ ```

1

miss

2020/04/19 07:14

投稿

hikaaaaaaaa
hikaaaaaaaa

スコア19

test CHANGED
@@ -1 +1 @@
1
- unity3D 捕まった場所の待機場所の実装
1
+ unity3D 捕まったプレイヤーの待機場所の実装
test CHANGED
File without changes