- Home /
Question by
SirOrange · Oct 29, 2017 at 05:15 PM ·
networkingmultiplayeranimatorphotonanimator controller
Is this not the correct way to setup an animator across the network?
My animation is only playing on the client it is on and is plays it for both characters.
using UnityEngine;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour
{
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
Animator anim;
void Start(){
anim = GetComponent<Animator> ();
if (anim == null) {
Debug.LogError ("Null Animator Component");
}
}
// Update is called once per frame
void Update()
{
if (photonView.isMine) {
}
else {
transform.position = Vector3.Lerp (transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp (transform.rotation, realRotation, 0.1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext (anim.GetInteger("run"));
}
else
{
// Network player, receive data
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext ();
anim.SetInteger("run", (int) stream.ReceiveNext ());
}
}
}
Comment
Answer by SirOrange · Oct 29, 2017 at 05:33 PM
When i say both characters, i mean both move on the client side, They play the same animation