Эта ошибка вписывала меня в тупик и мешала мне работать над следующим обновлением. Это дает эту ошибку только один раз, а затем все работает, я подумал, что это что -то еще, чем я отключил скрипт, и все работало нормально, просто ничего не синхронизировалось хорошо. Я довольно новичок в многопользовательской вещах, так что это действительно меня сбивает с толку. Может ли кто-нибудь, пожалуйста, мне помочь?using System;
using System.Collections;
using System.Collections.Generic;
using Photon.Pun;
using UnityEngine;
public class SlimeSync : MonoBehaviourPunCallbacks, IPunObservable
{
#region IPunObservable implementation
private SpriteRenderer spriteRenderer;
private PlayerControlledSlime slime;
private SlimeCustomization slimeCustomization;
private void Start(){
spriteRenderer = GetComponent();
slime = GetComponent();
slimeCustomization = Camera.main.GetComponentInChildren();
Camera.main.gameObject.GetComponentInChildren().GetComponent().AssignPlayer(gameObject);
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream == null || spriteRenderer == null || slime == null || slimeCustomization == null) return;
if (stream.IsWriting)
{
// We own this player: send the others our data
stream.SendNext(spriteRenderer.flipX);
stream.SendNext(slime.Slime);
stream.SendNext(slime.Hat);
stream.SendNext(slime.Animation);
}
else
{
// Network player, receive data
spriteRenderer.flipX = Convert.ToBoolean(stream.ReceiveNext());
int Slime = Convert.ToInt32(stream.ReceiveNext());
slime.AssignSlime(slimeCustomization.slimeObjects[Slime], Slime);
int Hat = Convert.ToInt32(stream.ReceiveNext());
slime.AssignHat(slimeCustomization.hatObjects[Hat], Hat);
int Animation = Convert.ToInt32(stream.ReceiveNext());
switch (Animation){
case 0:
spriteRenderer.sprite = slime.Normal;
break;
case 1:
spriteRenderer.sprite = slime.Squash;
break;
}
}
}
#endregion
}
< /code>
Полная ошибка < /p>
InvalidCastException: Specified cast is not valid.
Photon.Pun.PhotonTransformView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformView.cs:154)
Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:544)
Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:534)
Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1866)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2237)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3568)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:904)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:595)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1779)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:236)
Rethrow as AggregateException: Caught 1 exception(s) in methods called by DispatchIncomingCommands(). Rethrowing first only (see above).
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:254)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:156)
Подробнее здесь: https://stackoverflow.com/questions/794 ... -not-valid