質問編集履歴

3

細かいソースコードを載せたら

2018/03/21 08:03

投稿

aiueokakikukeko
aiueokakikukeko

スコア8

test CHANGED
@@ -1 +1 @@
1
- unity 増減するブロックの数え方
1
+ unity 増減するブロックの数え方(解決済み)
test CHANGED
@@ -1,629 +1,15 @@
1
- 小学生です。ユニティでブロック式の陣取りゲームを作っています。
1
+ 小学生です。ユニティでゲームを作っています。
2
2
 
3
- 最大4人対戦のゲームで、それぞれ自分の色があって、
3
+ 最大4人対戦のゲームで、それぞれ自分の陣地の色があって、
4
4
 
5
- 通ったところが自分の色に塗り替わる仕組みにして
5
+ 自分の色を数えたいのですが
6
6
 
7
- それぞれ自分の色を数えたいのですが、
8
-
9
- 通った道のり全部が数えられてしまいます。
10
-
11
- ちなみに一人目のタグがplayerで、二人目はcpu、3人目はcpu1、4人目はcpu2です。
12
-
13
- 宜しお願いたし
7
+ 上手くいせん
14
-
15
- ブロックのスクリプト☟
16
-
17
- ```C#
18
-
19
- using System.Collections;
20
-
21
- using System.Collections.Generic;
22
-
23
- using UnityEngine;
24
-
25
- using System;
26
-
27
- using System.Linq;
28
-
29
- public class BlockContller : MonoBehaviour {
30
-
31
- MeshRenderer meshrenderer;
32
-
33
- public Material playermaterial;
34
-
35
- public Material cpumaterial;
36
-
37
- public Material cpu1material;
38
-
39
- public Material cpu2material;
40
-
41
- public int zixyoutai = 1;
42
-
43
- public int zixyoutai1=0;
44
-
45
- public Vector3 pos;
46
-
47
- [SerializeField]
48
-
49
- MainCameraContller maincameracontller;
50
-
51
- int nantoka;
52
-
53
- [SerializeField]
54
-
55
- GameObject gamemanager;
56
-
57
- [SerializeField]
58
-
59
- GameObject Player;
60
-
61
- int zixyoutai2=0;
62
-
63
- Rigidbody rigbody;
64
-
65
- float time;
66
8
 
67
9
 
68
10
 
69
- // Use this for initialization
70
-
71
- void Start () {
72
-
73
- pos = this.transform.position;
74
-
75
- meshrenderer = GetComponent<MeshRenderer> ();
76
-
77
- rigbody = GetComponent<Rigidbody> ();
78
-
79
-
80
-
81
- }
82
-
83
-
84
-
85
- // Update is called once per frame
86
-
87
- void Update () {
11
+ 何か問題が予測出来ますでしょうか?
88
-
89
- if (gamemanager.GetComponent<PyotonContller> ().instantiteplayer == true) {
90
-
91
- Player = GameObject.FindGameObjectWithTag ("Player");
92
-
93
- }
94
-
95
- if (maincameracontller.animatorfinish == true) {
96
-
97
- if (zixyoutai2 == 1) {
98
-
99
-
100
-
101
- time += Time.deltaTime;
102
-
103
- if (time >= Player.GetComponent<PlayerContller> ().time * 5) {
104
-
105
- rigbody.isKinematic = false;
106
-
107
- }
108
-
109
- }
110
-
111
- }
112
-
113
- if (gamemanager.GetComponent<GameManager> ().blockriset == true) {
114
-
115
- gameObject.SetActive (true);
116
-
117
- transform.position = pos;
118
-
119
- }
120
-
121
- }
122
-
123
- void OnCollisionEnter(Collision collision){
124
-
125
- //if (gamemanager.GetComponent<GameManager> ().saiseiok==true) {
126
-
127
- //if (gamemanager.GetComponent<GameManager> ().onlineplayer == 4) {
128
-
129
- if(maincameracontller.animatorfinish==true){
130
-
131
- if (collision.gameObject.tag == "Player") {
132
-
133
- if (zixyoutai == 1) {
134
-
135
- // Debug.Log ("触れた");
136
-
137
- meshrenderer.material = playermaterial;
138
12
 
139
13
 
140
14
 
141
- gamemanager.GetComponent<GameManager> ().redblocknumber = gamemanager.GetComponent<GameManager> ().redblocknumber + 1;
142
-
143
- zixyoutai = 2;
144
-
145
- }
146
-
147
- if (zixyoutai >= 0) {
148
-
149
- zixyoutai2 = 1;
150
-
151
-
152
-
153
-
154
-
155
- }
156
-
157
- if (zixyoutai == 3) {
158
-
159
- if (meshrenderer.material == cpumaterial) {
160
-
161
- gamemanager.GetComponent<GameManager> ().blueblocknumber = gamemanager.GetComponent<GameManager> ().blueblocknumber - 1;
162
-
163
-
164
-
165
- } else if (meshrenderer.material == playermaterial) {
166
-
167
- gamemanager.GetComponent<GameManager> ().redblocknumber = gamemanager.GetComponent<GameManager> ().redblocknumber - 1;
168
-
169
- Debug.Log ("redblock-");
170
-
171
- } else if (meshrenderer.material == cpu1material) {
172
-
173
- gamemanager.GetComponent<GameManager> ().greenblocknumber = gamemanager.GetComponent<GameManager> ().greenblocknumber - 1;
174
-
175
- } else if (meshrenderer.material == cpu2material) {
176
-
177
- gamemanager.GetComponent<GameManager> ().orangeblocknumber = gamemanager.GetComponent<GameManager> ().orangeblocknumber - 1;
178
-
179
- }
180
-
181
- meshrenderer.material = playermaterial;
182
-
183
- gamemanager.GetComponent<GameManager> ().redblocknumber = gamemanager.GetComponent<GameManager> ().redblocknumber + 1;
184
-
185
- }
186
-
187
- }
188
-
189
- if (collision.gameObject.tag == "CPU") {
190
-
191
- if (zixyoutai == 1) {
192
-
193
- meshrenderer.material = cpumaterial;
194
-
195
- zixyoutai = 2;
196
-
197
- gamemanager.GetComponent<GameManager> ().blueblocknumber = gamemanager.GetComponent<GameManager> ().blueblocknumber + 1;
198
-
199
- }
200
-
201
- if (zixyoutai >= 0) {
202
-
203
- zixyoutai2 = 1;
204
-
205
- }
206
-
207
- if (zixyoutai == 3) {
208
-
209
-
210
-
211
- if (meshrenderer.material == cpumaterial) {
212
-
213
- gamemanager.GetComponent<GameManager> ().blueblocknumber = gamemanager.GetComponent<GameManager> ().blueblocknumber - 1;
214
-
215
- } else if (meshrenderer.material == playermaterial) {
216
-
217
- gamemanager.GetComponent<GameManager> ().redblocknumber = gamemanager.GetComponent<GameManager> ().redblocknumber - 1;
218
-
219
-
220
-
221
- } else if (meshrenderer.material == cpu1material) {
222
-
223
- gamemanager.GetComponent<GameManager> ().greenblocknumber = gamemanager.GetComponent<GameManager> ().greenblocknumber - 1;
224
-
225
- } else if (meshrenderer.material == cpu2material) {
226
-
227
- gamemanager.GetComponent<GameManager> ().orangeblocknumber = gamemanager.GetComponent<GameManager> ().orangeblocknumber - 1;
228
-
229
- }
230
-
231
- meshrenderer.material = cpumaterial;
232
-
233
- gamemanager.GetComponent<GameManager> ().blueblocknumber = gamemanager.GetComponent<GameManager> ().blueblocknumber + 1;
234
-
235
- }
236
-
237
- }
238
-
239
- if (collision.gameObject.tag == "CPU1") {
240
-
241
- if (zixyoutai == 1) {
242
-
243
- // Debug.Log ("触れた");
244
-
245
- meshrenderer.material = cpu1material;
246
-
247
- gamemanager.GetComponent<GameManager> ().greenblocknumber = gamemanager.GetComponent<GameManager> ().greenblocknumber + 1;
248
-
249
- zixyoutai = 2;
250
-
251
- }
252
-
253
- if (zixyoutai >= 0) {
254
-
255
- zixyoutai2 = 1;
256
-
257
-
258
-
259
-
260
-
261
- }
262
-
263
- if (zixyoutai == 3) {
264
-
265
- if (meshrenderer.material == cpumaterial) {
266
-
267
- gamemanager.GetComponent<GameManager> ().blueblocknumber = gamemanager.GetComponent<GameManager> ().blueblocknumber - 1;
268
-
269
-
270
-
271
- } else if (meshrenderer.material == playermaterial) {
272
-
273
- gamemanager.GetComponent<GameManager> ().redblocknumber = gamemanager.GetComponent<GameManager> ().redblocknumber - 1;
274
-
275
-
276
-
277
- } else if (meshrenderer.material == cpu1material) {
278
-
279
- gamemanager.GetComponent<GameManager> ().greenblocknumber = gamemanager.GetComponent<GameManager> ().greenblocknumber - 1;
280
-
281
- } else if (meshrenderer.material == cpu2material) {
282
-
283
- gamemanager.GetComponent<GameManager> ().orangeblocknumber = gamemanager.GetComponent<GameManager> ().orangeblocknumber - 1;
284
-
285
- }
286
-
287
- meshrenderer.material = cpu1material;
288
-
289
- gamemanager.GetComponent<GameManager> ().greenblocknumber = gamemanager.GetComponent<GameManager> ().greenblocknumber + 1;
290
-
291
-
292
-
293
-
294
-
295
- }
296
-
297
- }
298
-
299
-
300
-
301
-
302
-
303
- if (collision.gameObject.tag == "CPU2") {
304
-
305
- if (zixyoutai == 1) {
306
-
307
- // Debug.Log ("触れた");
308
-
309
- meshrenderer.material = cpu2material;
310
-
311
- zixyoutai = 2;
312
-
313
- gamemanager.GetComponent<GameManager> ().orangeblocknumber = gamemanager.GetComponent<GameManager> ().orangeblocknumber + 1;
314
-
315
- }
316
-
317
- if (zixyoutai >= 0) {
318
-
319
- zixyoutai2 = 1;
320
-
321
-
322
-
323
-
324
-
325
- }
326
-
327
-
328
-
329
- if (zixyoutai == 3) {
330
-
331
- if (meshrenderer.material == cpumaterial) {
332
-
333
- gamemanager.GetComponent<GameManager> ().blueblocknumber = gamemanager.GetComponent<GameManager> ().blueblocknumber - 1;
334
-
335
-
336
-
337
- } else if (meshrenderer.material == playermaterial) {
338
-
339
- gamemanager.GetComponent<GameManager> ().redblocknumber = gamemanager.GetComponent<GameManager> ().redblocknumber - 1;
340
-
341
-
342
-
343
- } else if (meshrenderer.material == cpu1material) {
344
-
345
- gamemanager.GetComponent<GameManager> ().greenblocknumber = gamemanager.GetComponent<GameManager> ().greenblocknumber - 1;
346
-
347
- } else if (meshrenderer.material == cpu2material) {
348
-
349
- gamemanager.GetComponent<GameManager> ().orangeblocknumber = gamemanager.GetComponent<GameManager> ().orangeblocknumber - 1;
350
-
351
- }
352
-
353
- meshrenderer.material = cpu2material;
354
-
355
- gamemanager.GetComponent<GameManager> ().orangeblocknumber = gamemanager.GetComponent<GameManager> ().orangeblocknumber + 1;
356
-
357
- }
358
-
359
- }
360
-
361
- if (collision.gameObject.tag == "water") {
362
-
363
- gameObject.SetActive (false);
364
-
365
- }
366
-
367
- //}
15
+ 宜しくお願いいたします。
368
-
369
- }
370
-
371
- }
372
-
373
- //}
374
-
375
-
376
-
377
- void OnCollisionExit(Collision collision){
378
-
379
- //if (gamemanager.GetComponent<GameManager> ().saiseiok==true){
380
-
381
-
382
-
383
- if (collision.gameObject.tag == "Player") {
384
-
385
- if (zixyoutai2 == 1) {
386
-
387
-
388
-
389
- zixyoutai2 = 0;
390
-
391
- time = 0f;
392
-
393
- }
394
-
395
- if (zixyoutai == 2) {
396
-
397
- zixyoutai = 3;
398
-
399
- return;
400
-
401
- }
402
-
403
- if (zixyoutai == 3) {
404
-
405
- // meshrenderer.material = playermaterial;
406
-
407
- zixyoutai1 = 1;
408
-
409
- rigbody.isKinematic = false;
410
-
411
-
412
-
413
- }
414
-
415
- }
416
-
417
- if (collision.gameObject.tag == "CPU") {
418
-
419
- if (zixyoutai2 == 1) {
420
-
421
-
422
-
423
- zixyoutai2 = 0;
424
-
425
- time = 0f;
426
-
427
- }
428
-
429
- if (zixyoutai == 2) {
430
-
431
- zixyoutai = 3;
432
-
433
- return;
434
-
435
- }
436
-
437
- if (zixyoutai == 3) {
438
-
439
- // meshrenderer.material = cpumaterial;
440
-
441
- zixyoutai1 = 1;
442
-
443
- rigbody.isKinematic = false;
444
-
445
-
446
-
447
- }
448
-
449
- }
450
-
451
- if (collision.gameObject.tag == "CPU1") {
452
-
453
- if (zixyoutai2 == 1) {
454
-
455
-
456
-
457
- zixyoutai2 = 0;
458
-
459
- time = 0f;
460
-
461
- }
462
-
463
- if (zixyoutai == 2) {
464
-
465
- zixyoutai = 3;
466
-
467
- return;
468
-
469
- }
470
-
471
- if (zixyoutai == 3) {
472
-
473
- //meshrenderer.material = cpu1material;
474
-
475
- zixyoutai1 = 1;
476
-
477
- rigbody.isKinematic = false;
478
-
479
-
480
-
481
- }
482
-
483
- }
484
-
485
- if (collision.gameObject.tag == "CPU2") {
486
-
487
- if (zixyoutai2 == 1) {
488
-
489
-
490
-
491
- zixyoutai2 = 0;
492
-
493
- time = 0f;
494
-
495
- }
496
-
497
- if (zixyoutai == 2) {
498
-
499
- zixyoutai = 3;
500
-
501
- return;
502
-
503
- }
504
-
505
- if (zixyoutai == 3) {
506
-
507
- //meshrenderer.material = cpu2material;
508
-
509
- zixyoutai1 = 1;
510
-
511
- rigbody.isKinematic = false;
512
-
513
-
514
-
515
- }
516
-
517
- }
518
-
519
-
520
-
521
- }
522
-
523
- }
524
-
525
- //}
526
-
527
-
528
-
529
- ```
530
-
531
- 補足情報
532
-
533
- ---
534
-
535
- GameManager
536
-
537
- ```C#
538
-
539
- using System.Collections;
540
-
541
- using System.Collections.Generic;
542
-
543
- using UnityEngine;
544
-
545
- using UnityEngine.UI;
546
-
547
- using System.Linq;
548
-
549
- public class GameManager : MonoBehaviour {
550
-
551
-
552
-
553
- public int redblocknumber;
554
-
555
- public int orangeblocknumber;
556
-
557
- public int greenblocknumber;
558
-
559
- public int blueblocknumber;
560
-
561
- public Text redblocktext;
562
-
563
- public Text orangeblocktext;
564
-
565
- public Text greenblocktext;
566
-
567
- public Text blueblocktext;
568
-
569
- public bool blockriset;
570
-
571
- public int onlineplayer;
572
-
573
- public Text onlineplayertext;
574
-
575
- public PyotonContller photoncontller;
576
-
577
- [SerializeField]
578
-
579
- GameObject player;
580
-
581
- //public bool saiseiok;
582
-
583
- // Use this for initialization
584
-
585
- void Start () {
586
-
587
-
588
-
589
- }
590
-
591
-
592
-
593
- // Update is called once per frame
594
-
595
- void Update () {
596
-
597
- redblocktext.text = "Redblock:" + redblocknumber;
598
-
599
- orangeblocktext.text = "OrangeBlock:" +orangeblocknumber;
600
-
601
- greenblocktext.text = "GreenBlock:" + greenblocknumber;
602
-
603
- blueblocktext.text = "BlueBlock:" + blueblocknumber;
604
-
605
- onlineplayertext.text="オンラインの人="+onlineplayer+"人";
606
-
607
- if (photoncontller.instantiteplayer == true) {
608
-
609
-
610
-
611
- player = GameObject.FindGameObjectWithTag ("Player");
612
-
613
- }
614
-
615
- }
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
-
624
-
625
- }
626
-
627
-
628
-
629
- ```

2

修正

2018/03/21 08:03

投稿

aiueokakikukeko
aiueokakikukeko

スコア8

test CHANGED
@@ -1 +1 @@
1
- unity ブロックの増減するブロックの数え方
1
+ unity 増減するブロックの数え方
test CHANGED
File without changes

1

内容の付け加え

2018/03/20 10:45

投稿

aiueokakikukeko
aiueokakikukeko

スコア8

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,9 @@
8
8
 
9
9
  通った道のり全部が数えられてしまいます。
10
10
 
11
- ちなみに一人目のタグがplayerで、二人目が、cpu3人目はcpu14人目はcpu2
11
+ ちなみに一人目のタグがplayerで、二人目cpu3人目はcpu14人目はcpu2です。
12
+
13
+ 宜しくお願いいたします。
12
14
 
13
15
  ブロックのスクリプト☟
14
16