質問編集履歴

2

コードを追加しました。

2020/04/30 14:03

投稿

creatorsGame
creatorsGame

スコア18

test CHANGED
File without changes
test CHANGED
@@ -51,3 +51,181 @@
51
51
 
52
52
 
53
53
  ![イメージ説明](233b76761edefd2d1c57c9a63fb5514d.gif)
54
+
55
+
56
+
57
+ 原因のプログラム
58
+
59
+ ```C#
60
+
61
+ 'Player'
62
+
63
+ using System.Collections;
64
+
65
+ using System.Collections.Generic;
66
+
67
+ using UnityEngine;
68
+
69
+ using Photon.Pun;
70
+
71
+
72
+
73
+ public class Player : MonoBehaviourPunCallbacks
74
+
75
+ {
76
+
77
+ public float walkSpeed = 3f;
78
+
79
+ public float runSpeed = 6f;
80
+
81
+ private CharacterController Controller;
82
+
83
+ private Vector3 velocity;
84
+
85
+ private Animator animator;
86
+
87
+ public Camera normalCam;
88
+
89
+ public GameObject CameraParent;
90
+
91
+ public float mouseSensitivity = 100f;
92
+
93
+ public Transform playerBody;
94
+
95
+ private float xRotation = 0f;
96
+
97
+ private bool runFlag = false;
98
+
99
+ [SerializeField]
100
+
101
+ private Transform spine;
102
+
103
+ private void Start()
104
+
105
+ {
106
+
107
+ animator = GetComponent<Animator>();
108
+
109
+ Controller = GetComponent<CharacterController>();
110
+
111
+ CameraParent.SetActive(photonView.IsMine);
112
+
113
+ }
114
+
115
+
116
+
117
+ private void Update()
118
+
119
+ {
120
+
121
+ if (!photonView.IsMine) return;
122
+
123
+ if (Controller.isGrounded)
124
+
125
+ {
126
+
127
+ velocity = Vector3.zero;
128
+
129
+ var horizontal = Input.GetAxis("Horizontal");
130
+
131
+ var vertical = Input.GetAxis("Vertical");
132
+
133
+ velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized;
134
+
135
+
136
+
137
+ float speed = 0f;
138
+
139
+ if (Input.GetButton("Run") && Input.GetKey(KeyCode.W) && (!Input.GetButton("Fire2")))
140
+
141
+ {
142
+
143
+ runFlag = true;
144
+
145
+ speed = runSpeed;
146
+
147
+ }
148
+
149
+ else
150
+
151
+ {
152
+
153
+ runFlag = false;
154
+
155
+ speed = walkSpeed;
156
+
157
+ }
158
+
159
+ velocity *= speed;
160
+
161
+ if (velocity.magnitude > 0)
162
+
163
+ {
164
+
165
+ animator.SetFloat("MoveX", horizontal);
166
+
167
+ animator.SetFloat("MoveY", vertical);
168
+
169
+ if (runFlag && Input.GetKey(KeyCode.W) && (!Input.GetButton("Fire2"))) { animator.SetFloat("Speed", 2.1f); }
170
+
171
+ else
172
+
173
+ {
174
+
175
+ animator.SetFloat("Speed", 0f);
176
+
177
+ }
178
+
179
+ }
180
+
181
+ else
182
+
183
+ {
184
+
185
+ animator.SetFloat("Speed", 0f);
186
+
187
+ animator.SetFloat("MoveX", 0f);
188
+
189
+ animator.SetFloat("MoveY", 0f);
190
+
191
+ }
192
+
193
+ }
194
+
195
+ velocity.y += Physics.gravity.y * Time.deltaTime;
196
+
197
+ Controller.Move(velocity * Time.deltaTime);
198
+
199
+ }
200
+
201
+ private void LateUpdate()
202
+
203
+ {
204
+
205
+ if (!photonView.IsMine) return;
206
+
207
+ float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
208
+
209
+ float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
210
+
211
+ xRotation -= mouseY;
212
+
213
+ xRotation = Mathf.Clamp(xRotation, -50, 40);
214
+
215
+ playerBody.Rotate(Vector3.up * mouseX);
216
+
217
+ spine.rotation = Quaternion.Euler(spine.eulerAngles.x + xRotation, spine.eulerAngles.y, spine.eulerAngles.z);
218
+
219
+ spine.localEulerAngles = new Vector3(xRotation, 0, 0);
220
+
221
+ normalCam.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
222
+
223
+ }
224
+
225
+ }
226
+
227
+
228
+
229
+
230
+
231
+ ```

1

全てのエラー内容を載せました。

2020/04/30 14:02

投稿

creatorsGame
creatorsGame

スコア18

test CHANGED
File without changes
test CHANGED
@@ -1,617 +1,53 @@
1
+ ```
2
+
3
+ エラー
4
+
1
5
  MissingReferenceException: The object of type 'PhotonView' has been destroyed but you are still trying to access it.
2
6
 
3
7
  Your script should either check if it is null or you should not destroy the object.
4
8
 
5
- というエラーがでて困っています。どこをどう変更すればよいのでしょうか?
9
+ Photon.Pun.PhotonNetwork.LocalCleanupAnythingInstantiated (System.Boolean destroyInstantiatedGameObjects) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:269)
6
10
 
7
- 自分でもいろいろ調べて試してみたのですが、どこを変えればよいのか分かりませんでした。
11
+ Photon.Pun.PhotonNetwork.LeftRoomCleanup () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:245)
8
12
 
9
- あと、関係すると思われるスクリプトだけを貼りました。
13
+ Photon.Pun.PhotonNetwork+<>c.<.cctor>b__124_0 (Photon.Realtime.ClientState previousState, Photon.Realtime.ClientState state) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1006)
10
14
 
11
- Player
15
+ Photon.Realtime.LoadBalancingClient.set_State (Photon.Realtime.ClientState value) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:383)
12
16
 
13
- ```c#
17
+ Photon.Realtime.LoadBalancingClient.Disconnect (Photon.Realtime.DisconnectCause cause) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:1067)
14
18
 
15
- using System.Collections;
19
+ Photon.Realtime.ConnectionHandler.OnDisable () (at Assets/Photon/PhotonRealtime/Code/ConnectionHandler.cs:91)
16
20
 
17
- using System.Collections.Generic;
18
-
19
- using UnityEngine;
20
-
21
- using Photon.Pun;
22
-
23
-
24
-
25
- public class Player : MonoBehaviourPunCallbacks
26
-
27
- {
28
-
29
- public float walkSpeed = 3f;
30
-
31
- public float runSpeed = 6f;
32
-
33
- private CharacterController Controller;
34
-
35
- private Vector3 velocity;
36
-
37
- private Animator animator;
38
-
39
- public Camera normalCam;
40
-
41
- public GameObject CameraParent;
42
-
43
- public float mouseSensitivity = 100f;
44
-
45
- public Transform playerBody;
46
-
47
- private float xRotation = 0f;
48
-
49
- private bool runFlag = false;
50
-
51
- [SerializeField]
52
-
53
- private Transform spine;
54
-
55
- void Start()
56
-
57
- {
58
-
59
- animator = GetComponent<Animator>();
60
-
61
- Controller = GetComponent<CharacterController>();
62
-
63
- CameraParent.SetActive(photonView.IsMine);
64
-
65
- }
66
-
67
-
68
-
69
- void Update()
70
-
71
- {
72
-
73
- if (!photonView.IsMine) return;
74
-
75
- if (Controller.isGrounded)
76
-
77
- {
78
-
79
- velocity = Vector3.zero;
80
-
81
- var horizontal = Input.GetAxis("Horizontal");
82
-
83
- var vertical = Input.GetAxis("Vertical");
84
-
85
- velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized;
21
+ Photon.Pun.PhotonHandler.OnDisable () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:132)
86
-
87
-
88
-
89
- float speed = 0f;
90
-
91
- if (Input.GetButton("Run") && Input.GetKey(KeyCode.W))
92
-
93
- {
94
-
95
- runFlag = true;
96
-
97
- speed = runSpeed;
98
-
99
- }
100
-
101
- else
102
-
103
- {
104
-
105
- runFlag = false;
106
-
107
- speed = walkSpeed;
108
-
109
- }
110
-
111
- velocity *= speed;
112
-
113
- if (velocity.magnitude > 0)
114
-
115
- {
116
-
117
- animator.SetFloat("MoveX", horizontal);
118
-
119
- animator.SetFloat("MoveY", vertical);
120
-
121
- if (runFlag&&Input.GetKey(KeyCode.W)) animator.SetFloat("Speed", 2.1f);
122
-
123
- }
124
-
125
- else
126
-
127
- {
128
-
129
- animator.SetFloat("Speed", 0f);
130
-
131
- animator.SetFloat("MoveX", 0f);
132
-
133
- animator.SetFloat("MoveY", 0f);
134
-
135
- }
136
-
137
- }
138
-
139
- velocity.y += Physics.gravity.y * Time.deltaTime;
140
-
141
- Controller.Move(velocity * Time.deltaTime);
142
-
143
- }
144
-
145
- private void LateUpdate()
146
-
147
- {
148
-
149
- if (!photonView.IsMine) return;
150
-
151
- float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
152
-
153
- float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
154
-
155
- xRotation -= mouseY;
156
-
157
- xRotation = Mathf.Clamp(xRotation, -50, 40);
158
-
159
- playerBody.Rotate(Vector3.up * mouseX);
160
-
161
- spine.rotation = Quaternion.Euler(spine.eulerAngles.x + xRotation, spine.eulerAngles.y, spine.eulerAngles.z);
162
-
163
- spine.localEulerAngles = new Vector3(xRotation, 0, 0);
164
-
165
- normalCam.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
166
-
167
- }
168
-
169
- }
170
22
 
171
23
  ```
172
24
 
25
+ ```
173
26
 
27
+ 注意マーク
174
28
 
175
- Weapon
29
+ PUN is in development mode (development build). As the 'dev region' is not empty (jp) it overrides the found best region. See PhotonServerSettings.
176
30
 
177
- ```c#
31
+ UnityEngine.Debug:LogWarning(Object)
178
32
 
179
- using UnityEngine;
33
+ Photon.Pun.PhotonNetwork:OnRegionsPinged(RegionHandler) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2312)
180
34
 
181
- using Photon.Pun;
35
+ Photon.Realtime.RegionHandler:OnPreferredRegionPinged(Region) (at Assets/Photon/PhotonRealtime/Code/RegionHandler.cs:251)
182
36
 
183
- public class Weapon : MonoBehaviourPunCallbacks
37
+ Photon.Realtime.RegionPinger:RegionPingThreaded() (at Assets/Photon/PhotonRealtime/Code/RegionHandler.cs:459)
184
38
 
185
- {
39
+ ExitGames.Client.Photon.<>c__DisplayClass6_0:<StartBackgroundCalls>b__0()
186
40
 
187
- private Animator anim;
188
-
189
- private AudioSource audioSource;
190
-
191
- public AudioClip ShootSound;
192
-
193
- public float range = 100f;
194
-
195
- public int bulletsPerMag = 30;
196
-
197
- public int bulletsLeft = 200;
198
-
199
- public int currentBullets;
200
-
201
- public enum ShootMode { Auto, Semi }
202
-
203
- public ShootMode shootingMode;
204
-
205
- public Transform muzzle;
206
-
207
- public ParticleSystem muzzleFlash;
208
-
209
- public GameObject hitParticles;
210
-
211
- public GameObject bulletImpact;
212
-
213
- public float fireRate = 0.1f;
214
-
215
- public float damage = 20f;
216
-
217
- float fireTimer;
218
-
219
- private bool isReloading;
220
-
221
- private bool shootInput;
222
-
223
- public Vector3 aimPosition;
224
-
225
- public float aodSpeed = 8f;
226
-
227
- public Recoil recoil;
228
-
229
- public Vector3 walkPosition;
230
-
231
- public Vector3 walkPosition2;
232
-
233
- public float walkSpeed = 2f;
234
-
235
- private Vector3 controlPoint;
236
-
237
- private float walkDistance;
238
-
239
- public Vector3 aimPosition2;
240
-
241
- public float walkSpeed2 = 2f;
242
-
243
- private Vector3 controlPoint2;
244
-
245
- private float walkDistance2;
246
-
247
-
248
-
249
- private Vector3 testPosition;
250
-
251
- private Vector3 testPosition2;
252
-
253
-
254
-
255
- private void Start()
256
-
257
- {
258
-
259
- anim = GetComponent<Animator>();
260
-
261
- audioSource = GetComponent<AudioSource>();
262
-
263
- controlPoint = (walkPosition + walkPosition2) * 0.5f;
264
-
265
- controlPoint.y += Vector3.Distance(walkPosition, walkPosition2);
266
-
267
-
268
-
269
- controlPoint2 = (aimPosition + aimPosition2) * 0.5f;
270
-
271
- controlPoint2.y += Vector3.Distance(aimPosition, aimPosition2);
272
-
273
- testPosition2 = aimPosition;
274
-
275
- currentBullets = bulletsPerMag;
276
-
277
- }
278
-
279
- private void Update()
280
-
281
- {
282
-
283
- if (!photonView.IsMine) return;
284
-
285
- if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)) && !(Input.GetButton("Fire2")))
286
-
287
- {
288
-
289
- walkDistance += Time.deltaTime * walkSpeed;
290
-
291
- var t = Mathf.PingPong(walkDistance, 1.0f);
292
-
293
- testPosition = EvaluatePosition(ModulateParameter(t));
294
-
295
- }
296
-
297
- if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))&& (Input.GetButton("Fire2")))
298
-
299
- {
300
-
301
- walkDistance2 += Time.deltaTime * walkSpeed2;
302
-
303
- var t = Mathf.PingPong(walkDistance2, 1.0f);
304
-
305
- testPosition2 = EvaluatePosition2(ModulateParameter2(t));
306
-
307
- }
308
-
309
-
310
-
311
- if (Input.GetButton("Run") && Input.GetKey(KeyCode.W))
312
-
313
- {
314
-
315
- anim.SetFloat("Speed", 2.1f);
316
-
317
- }
318
-
319
- else
320
-
321
- {
322
-
323
- anim.SetFloat("Speed", 0f);
324
-
325
- }
326
-
327
-
328
-
329
- switch (shootingMode)
330
-
331
- {
332
-
333
- case ShootMode.Auto:
334
-
335
- shootInput = Input.GetButton("Fire1");
336
-
337
- break;
338
-
339
- case ShootMode.Semi:
340
-
341
- shootInput = Input.GetButtonDown("Fire1");
342
-
343
- break;
344
-
345
- }
346
-
347
- if (shootInput)
348
-
349
- {
350
-
351
- if (currentBullets > 0)
352
-
353
- Fire();
354
-
355
- else if (bulletsLeft > 0)
356
-
357
- DoReload();
358
-
359
- }
360
-
361
-
362
-
363
- if (Input.GetKeyDown(KeyCode.R))
364
-
365
- {
366
-
367
- if (currentBullets < bulletsPerMag && bulletsLeft > 0)
368
-
369
- DoReload();
370
-
371
- }
372
-
373
-
374
-
375
- if (fireTimer < fireRate)
376
-
377
- {
378
-
379
- fireTimer += Time.deltaTime;
380
-
381
- }
382
-
383
- AimDownSights();
384
-
385
- }
386
-
387
-
388
-
389
- private void FixedUpdate()
390
-
391
- {
392
-
393
- if (!photonView.IsMine) return;
394
-
395
- AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
396
-
397
- isReloading = info.IsName("Reload");
41
+ System.Threading.ThreadHelper:ThreadStart()
398
-
399
- }
400
-
401
- private void AimDownSights()
402
-
403
- {
404
-
405
- if (Input.GetButton("Fire2") && !isReloading)
406
-
407
- {
408
-
409
- transform.localPosition= Vector3.Lerp(transform.localPosition, testPosition2, Time.deltaTime * aodSpeed);
410
-
411
- recoil.aim = true;
412
-
413
- }
414
-
415
- else
416
-
417
- {
418
-
419
- transform.localPosition = Vector3.Lerp(transform.localPosition, testPosition, Time.deltaTime * aodSpeed);
420
-
421
- recoil.aim = false;
422
-
423
- }
424
-
425
- }
426
-
427
- private void Fire()
428
-
429
- {
430
-
431
- if (fireTimer < fireRate || currentBullets <= 0 || isReloading) return;
432
-
433
- recoil.Fire();
434
-
435
- RaycastHit hit;
436
-
437
- if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit, range))
438
-
439
- {
440
-
441
- Debug.Log(hit.transform.name + "found");
442
-
443
- GameObject hitParticleEffect = Instantiate(hitParticles, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
444
-
445
- GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));
446
-
447
- Destroy(hitParticleEffect, 1f);
448
-
449
- Destroy(bulletHole, 2f);
450
-
451
- if (hit.transform.GetComponent<Health>())
452
-
453
- {
454
-
455
- hit.transform.GetComponent<Health>().ApplyDamage(damage);
456
-
457
- }
458
-
459
- }
460
-
461
- anim.CrossFadeInFixedTime("Shoot", 0.01f);
462
-
463
- muzzleFlash.Play();
464
-
465
- PlayShootSound();
466
-
467
- currentBullets--;
468
-
469
- fireTimer = 0.0f;
470
-
471
- }
472
-
473
- private void Reload()
474
-
475
- {
476
-
477
- if (bulletsLeft <= 0) return;
478
-
479
-
480
-
481
- int bulletsToLoad = bulletsPerMag - currentBullets;
482
-
483
- int bulletsToDeduct = (bulletsLeft >= bulletsToLoad) ? bulletsToLoad : bulletsLeft;
484
-
485
-
486
-
487
- bulletsLeft -= bulletsToDeduct;
488
-
489
- currentBullets += bulletsToDeduct;
490
-
491
- }
492
-
493
- private void DoReload()
494
-
495
- {
496
-
497
- AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
498
-
499
-
500
-
501
- if (isReloading) return;
502
-
503
- anim.CrossFadeInFixedTime("Reload", 0.01f);
504
-
505
- }
506
-
507
- private void PlayShootSound()
508
-
509
- {
510
-
511
- audioSource.PlayOneShot(ShootSound);
512
-
513
- }
514
-
515
- private static float ModulateParameter(float t)
516
-
517
- {
518
-
519
- if (t < 0.5f)
520
-
521
- {
522
-
523
- t *= 2.0f;
524
-
525
- t = t * t * 0.5f;
526
-
527
- }
528
-
529
- else
530
-
531
- {
532
-
533
- t = (1.0f - t) * 2.0f;
534
-
535
- t = t * t * 0.5f;
536
-
537
- t = 1.0f - t;
538
-
539
- }
540
-
541
-
542
-
543
- return t;
544
-
545
- }
546
-
547
- private static float ModulateParameter2(float t)
548
-
549
- {
550
-
551
- if (t < 0.5f)
552
-
553
- {
554
-
555
- t *= 2.0f;
556
-
557
- t = t * t * 0.5f;
558
-
559
- }
560
-
561
- else
562
-
563
- {
564
-
565
- t = (1.0f - t) * 2.0f;
566
-
567
- t = t * t * 0.5f;
568
-
569
- t = 1.0f - t;
570
-
571
- }
572
-
573
-
574
-
575
- return t;
576
-
577
- }
578
-
579
- private Vector3 EvaluatePosition(float t)
580
-
581
- {
582
-
583
- var it = 1.0f - t;
584
-
585
- var f0 = it * it;
586
-
587
- var f1 = it * t * 2.0f;
588
-
589
- var f2 = t * t;
590
-
591
- return (walkPosition * f0) + (controlPoint * f1) + (walkPosition2 * f2);
592
-
593
- }
594
-
595
-
596
-
597
- private Vector3 EvaluatePosition2(float t)
598
-
599
- {
600
-
601
- var it = 1.0f - t;
602
-
603
- var f0 = it * it;
604
-
605
- var f1 = it * t * 2.0f;
606
-
607
- var f2 = t * t;
608
-
609
- return (aimPosition * f0) + (controlPoint2 * f1) + (aimPosition2 * f2);
610
-
611
- }
612
-
613
- }
614
42
 
615
43
 
616
44
 
617
45
  ```
46
+
47
+ 上記のエラーと注意マークが出て困っています。Photon2関係のスクリプトはいじっていないのでエラーで示されているスクリプトは関係がないと自分は思っているのですが、載せないと分からない場合はご指摘お願いいたします。
48
+
49
+ また、実際に起きている問題としては以下のように片方のプレイヤーが落ちたり、元の位置に戻ったりが繰り返されます。
50
+
51
+
52
+
53
+ ![イメージ説明](233b76761edefd2d1c57c9a63fb5514d.gif)