- Home /
Sync animaor of child prefab
I all, i spend a lot of time to try sync animation of my player prefab ( Humanoid basic on asset store 10€ ) over the photon network but I still did not. I have a prefab call "Giocatore" and it's have two child object, "Camera" and "Animator". The camera controller already work and it have no lag where there are more than one player on the room. The problem come when i try to sync the animation of the child object called "Animator" of my prefab "Giocatore".
I'm new on the animator scene and i don't know why on the prefab the child object call "Animator" doesn't have another child obejct. When i press play, the photon instantiate my prefab call "Giocatore" and on the scene i see the child "Animator" have more child object, for example: back_shield, cloth, elbow_armor, hand_shield, warrior_body, etc.
That is my player network script:
using UnityEngine;
using System.Collections;
public class PlayerNetwork : Photon.MonoBehaviour
{
public Camera myCamera;
public AudioListener listener;
private Animator playerAnimator;
private Vector3 correctPlayerPos;
private Quaternion correctPlayerRot;
void Awake()
{
playerAnimator = gameObject.GetComponentInChildren<Animator>();
}
// Use this for initialization
void Start()
{
if (photonView.isMine)
{
myCamera.enabled = true;
// listener.enabled = true;
this.GetComponent<Controller>().enabled = true;
}
}
void Update()
{
if (!photonView.isMine)
{
transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
Debug.Log("Classe");
if (stream.isWriting)
{
Debug.Log("Writing in..");
// We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
// stream.SendNext(playerAnimator.GetFloat("Speed"));
Debug.Log("Writing fine..");
}
else
{
Debug.Log("Get data inizio");
// Network player, receive data
this.correctPlayerPos = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
// playerAnimator.SetFloat("Speed", (float)stream.ReceiveNext());
Debug.Log("Get data fine");
}
}
}
How i can sync the animation?
IMG1: https://ibb.co/jtV5Ok
IMG2: https://ibb.co/i2oEG5
Thanks!