- Home /
Question by
ivanbozovic · Jul 19, 2015 at 07:27 PM ·
photonanimationssync
PLEASE HELP with Photon!
Hi,
I have a script that syncs position, and rotation. I am trying to add syncing animations. I HAVE writter animation code 100% correctly I tested it. But I can't see what am I doing wrong. This is driving me crazy for a couple of days already! Here is the 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<Animation>().CrossFade(standingRun.name);
}
if(useThisMove == 2)
{
characterModel.GetComponent<Animation>().CrossFade(standingIdle.name);
}
if(useThisMove == 3)
{
characterModel.GetComponent<Animation>().CrossFade(standingWalk.name);
}
if(useThisMove == 4)
{
characterModel.GetComponent<Animation>().CrossFade(crouchIdle.name);
}
if(useThisMove == 5)
{
characterModel.GetComponent<Animation>().CrossFade(crouchWalk.name);
}
if(useThisMove == 6)
{
characterModel.GetComponent<Animation>().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();
}
}
}
Thanks in advance!
Comment
Where is useThis$$anonymous$$ove set? What is affecting it? Is it usually 0 or usually > 0? You should debug that value by showing it in some gui. Show it locally and for each remote character, too. So you have an idea if it arrives as you expect.