エラー MissingReferenceException: The object of type 'PhotonView' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. Photon.Pun.PhotonNetwork.LocalCleanupAnythingInstantiated (System.Boolean destroyInstantiatedGameObjects) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:269) Photon.Pun.PhotonNetwork.LeftRoomCleanup () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:245) Photon.Pun.PhotonNetwork+<>c.<.cctor>b__124_0 (Photon.Realtime.ClientState previousState, Photon.Realtime.ClientState state) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1006) Photon.Realtime.LoadBalancingClient.set_State (Photon.Realtime.ClientState value) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:383) Photon.Realtime.LoadBalancingClient.Disconnect (Photon.Realtime.DisconnectCause cause) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:1067) Photon.Realtime.ConnectionHandler.OnDisable () (at Assets/Photon/PhotonRealtime/Code/ConnectionHandler.cs:91) Photon.Pun.PhotonHandler.OnDisable () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:132)
注意マーク PUN is in development mode (development build). As the 'dev region' is not empty (jp) it overrides the found best region. See PhotonServerSettings. UnityEngine.Debug:LogWarning(Object) Photon.Pun.PhotonNetwork:OnRegionsPinged(RegionHandler) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2312) Photon.Realtime.RegionHandler:OnPreferredRegionPinged(Region) (at Assets/Photon/PhotonRealtime/Code/RegionHandler.cs:251) Photon.Realtime.RegionPinger:RegionPingThreaded() (at Assets/Photon/PhotonRealtime/Code/RegionHandler.cs:459) ExitGames.Client.Photon.<>c__DisplayClass6_0:<StartBackgroundCalls>b__0() System.Threading.ThreadHelper:ThreadStart()
上記のエラーと注意マークが出て困っています。Photon2関係のスクリプトはいじっていないのでエラーで示されているスクリプトは関係がないと自分は思っているのですが、載せないと分からない場合はご指摘お願いいたします。
また、実際に起きている問題としては以下のように片方のプレイヤーが落ちたり、元の位置に戻ったりが繰り返されます。
原因のプログラム
C#
1'Player' 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using Photon.Pun; 6 7public class Player : MonoBehaviourPunCallbacks 8{ 9 public float walkSpeed = 3f; 10 public float runSpeed = 6f; 11 private CharacterController Controller; 12 private Vector3 velocity; 13 private Animator animator; 14 public Camera normalCam; 15 public GameObject CameraParent; 16 public float mouseSensitivity = 100f; 17 public Transform playerBody; 18 private float xRotation = 0f; 19 private bool runFlag = false; 20 [SerializeField] 21 private Transform spine; 22 private void Start() 23 { 24 animator = GetComponent<Animator>(); 25 Controller = GetComponent<CharacterController>(); 26 CameraParent.SetActive(photonView.IsMine); 27 } 28 29 private void Update() 30 { 31 if (!photonView.IsMine) return; 32 if (Controller.isGrounded) 33 { 34 velocity = Vector3.zero; 35 var horizontal = Input.GetAxis("Horizontal"); 36 var vertical = Input.GetAxis("Vertical"); 37 velocity = (transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")).normalized; 38 39 float speed = 0f; 40 if (Input.GetButton("Run") && Input.GetKey(KeyCode.W) && (!Input.GetButton("Fire2"))) 41 { 42 runFlag = true; 43 speed = runSpeed; 44 } 45 else 46 { 47 runFlag = false; 48 speed = walkSpeed; 49 } 50 velocity *= speed; 51 if (velocity.magnitude > 0) 52 { 53 animator.SetFloat("MoveX", horizontal); 54 animator.SetFloat("MoveY", vertical); 55 if (runFlag && Input.GetKey(KeyCode.W) && (!Input.GetButton("Fire2"))) { animator.SetFloat("Speed", 2.1f); } 56 else 57 { 58 animator.SetFloat("Speed", 0f); 59 } 60 } 61 else 62 { 63 animator.SetFloat("Speed", 0f); 64 animator.SetFloat("MoveX", 0f); 65 animator.SetFloat("MoveY", 0f); 66 } 67 } 68 velocity.y += Physics.gravity.y * Time.deltaTime; 69 Controller.Move(velocity * Time.deltaTime); 70 } 71 private void LateUpdate() 72 { 73 if (!photonView.IsMine) return; 74 float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; 75 float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; 76 xRotation -= mouseY; 77 xRotation = Mathf.Clamp(xRotation, -50, 40); 78 playerBody.Rotate(Vector3.up * mouseX); 79 spine.rotation = Quaternion.Euler(spine.eulerAngles.x + xRotation, spine.eulerAngles.y, spine.eulerAngles.z); 80 spine.localEulerAngles = new Vector3(xRotation, 0, 0); 81 normalCam.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); 82 } 83} 84 85
破棄されたゲームオブジェクトを格納した変数を参照している際に出るエラーです。
どこでエラーが発生しているかが書かれていないため、どこを変更すればいいのかは分かりません。
回答2件
あなたの回答
tips
プレビュー