Quantcast
Channel: Latest Questions by ivanbozovic
Viewing all articles
Browse latest Browse all 9

Photon animation syncing

$
0
0
Hi, I am trying to sync LEGACY animations with Photon. I can't see what is wrong in this script: using UnityEngine; using System.Collections; public class NetworkPlayer : Photon.MonoBehaviour { Vector3 realPosition = Vector3.zero; Quaternion realRotation = Quaternion.identity; public Animation characterModel; public AnimationClip crouchIdle; public AnimationClip crouchWalk; public AnimationClip standingIdle; public AnimationClip standingWalk; public AnimationClip standingRun; public AnimationClip jump; int useThisMove; void Update() { if(!photonView.isMine) { transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f); transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f); } if(useThisMove == 1) { characterModel.GetComponent().CrossFade(standingRun.name); } if(useThisMove == 2) { characterModel.GetComponent().CrossFade(standingIdle.name); } if(useThisMove == 3) { characterModel.GetComponent().CrossFade(standingWalk.name); } if(useThisMove == 4) { characterModel.GetComponent().CrossFade(crouchIdle.name); } if(useThisMove == 5) { characterModel.GetComponent().CrossFade(crouchWalk.name); } if(useThisMove == 6) { characterModel.GetComponent().CrossFade(jump.name); } } public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { stream.SendNext(transform.position); stream.SendNext(transform.rotation); if(characterModel.IsPlaying(standingRun.name)) { stream.SendNext(useThisMove = 1); } if(characterModel.IsPlaying(standingIdle.name)) { stream.SendNext(useThisMove = 2); } if(characterModel.IsPlaying(standingWalk.name)) { stream.SendNext(useThisMove = 3); } if(characterModel.IsPlaying(crouchIdle.name)) { stream.SendNext(useThisMove = 4); } if(characterModel.IsPlaying(crouchWalk.name)) { stream.SendNext(useThisMove = 5); } if(characterModel.IsPlaying(jump.name)) { stream.SendNext(useThisMove = 6); } } else { realPosition = (Vector3)stream.ReceiveNext(); realRotation = (Quaternion)stream.ReceiveNext(); useThisMove = (int)stream.ReceiveNext(); } } } It gives me this error: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[System.Object].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) PhotonStream.ReceiveNext () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonClasses.cs:1024) NetworkPlayer.OnPhotonSerializeView (.PhotonStream stream, .PhotonMessageInfo info) (at Assets/_Scripts/Networking/NetworkPlayer.cs:94) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) PhotonView.ExecuteComponentOnSerialize (UnityEngine.Component component, .PhotonStream stream, .PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:536) PhotonView.DeserializeComponent (UnityEngine.Component component, .PhotonStream stream, .PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:367) PhotonView.DeserializeView (.PhotonStream stream, .PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:352) NetworkingPeer.OnSerializeRead (ExitGames.Client.Photon.Hashtable data, .PhotonPlayer sender, Int32 networkTime, Int16 correctPrefix) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3498) NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1924) ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff) ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83) Thanks in advance!

Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>