- Home /
Network animation sync, problem.
Hello, I have a networked game, and tried to make the animations sync for my third person viewed guy(The guy displayed over the network.), but it does not play the animations. I have a Empty game object called player with the scripts UserPlayer and NetworkAnimation(Also a network view) applied to it, then a ThirdPerson viewed object with an animation component(And all stated animations), and a First person object, with Network animation controller attached. Also all Variables were assigned, here are all my scripts.
UserPlayer:
using UnityEngine;
using System.Collections;
public class UserPlayer : MonoBehaviour {
public Transform FirstPerson;
public WeaponManager FirstPersonCont;
public Transform ThirdPerson;
public Player MyPlayer;
public GameObject Ragdoll;
public Vector3 CurPos;
public Quaternion CurRot;
// Use this for initialization
void Start () {
MyPlayer = NetworkManager.GetPlayer(networkView.owner);
MyPlayer.Manager = this;
FirstPerson.gameObject.SetActive(false);
ThirdPerson.gameObject.SetActive(false);
DontDestroyOnLoad(gameObject);
}
// Update is called once per frame
void Update () {
}
[RPC]
void Server_TakeDamage(float Damage){
networkView.RPC("Client_TakeDamage",RPCMode.Server,Damage);
}
[RPC]
void Client_TakeDamage(float Damage){
MyPlayer.Health -= Damage;
Debug.Log("Player Has Been Shot! " + MyPlayer.Health);
if(MyPlayer.Health <= 0){
networkView.RPC("Die",RPCMode.All);
MyPlayer.isAlive = false;
MyPlayer.Health = 0;
Instantiate(Ragdoll,ThirdPerson.position,ThirdPerson.rotation);
}
}
[RPC]
void Spawn(){
MyPlayer.Health = 100;
MyPlayer.isAlive = true;
if(networkView.isMine){
FirstPerson.gameObject.SetActive(true);
ThirdPerson.gameObject.SetActive(false);
}
else{
FirstPerson.gameObject.SetActive(false);
ThirdPerson.gameObject.SetActive(true);
}
}
[RPC]
void Die(){
MyPlayer.isAlive = false;
FirstPerson.gameObject.SetActive(false);
ThirdPerson.gameObject.SetActive(false);
}
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info){
if(stream.isWriting){
CurPos = FirstPerson.position;
CurRot = FirstPerson.rotation;
stream.Serialize(ref CurPos);
stream.Serialize(ref CurRot);
char Ani = (char)GetComponent<NetworkAnimation>().CurrentAnim;
stream.Serialize(ref Ani);
}
else{
stream.Serialize(ref CurPos);
stream.Serialize(ref CurRot);
ThirdPerson.position = CurPos;
ThirdPerson.rotation = CurRot;
char Ani = (char)0;
stream.Serialize(ref Ani);
GetComponent<NetworkAnimation>().CurrentAnim = (Animations)Ani;
}
}
}
NetworkAnimation:
using UnityEngine;
using System.Collections;
using System;
public class NetworkAnimation : MonoBehaviour {
public Animations CurrentAnim = Animations.Primary_Idle_1;
public GameObject ThirdPersonPlayer;
void Update(){
ThirdPersonPlayer.animation.CrossFade(Enum.GetName(typeof(Animations),CurrentAnim));
}
public void SyncAnim(string animname, float Speed){
CurrentAnim = (Animations)Enum.Parse(typeof(Animations),animname);
animation[CurrentAnim.ToString()].speed = Speed;
}
}
public enum Animations{
Primary_Idle_1,
Primary_Walk_1,
Primary_Reload_1
}
Network Animation Controller:
using UnityEngine;
using System.Collections;
public class NetworkAnimationController : MonoBehaviour {
public float V;
public float H;
public NetworkAnimation States;
void Update(){
V = Input.GetAxis("Vertical");
H = Input.GetAxis("Horizontal");
if(V < 0){
States.SyncAnim("Primary_Walk_1",1);
}
if(V > 0){
States.SyncAnim("Primary_Walk_1",1);
}
else{
States.SyncAnim("Primary_Idle_1",1);
}
}
}
Do you get any errors? Have you tried debugging your script? If so what are your results? If not, please do so before you ask questions
No errors with code, if I put thirdperson.animation.speed thing, did you see anything wrong with the code.
Is your NetworkView actually observing the component you want to transfer over the network? They default to the Transform of the GameObject they're attached.
Yes the user player is being observed, but it just isnt playing the animations, and the animations are named right for what im asking from the script. Did you see anything wrong?
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unhandled message error when registering host 1 Answer
Animations not working like they should 0 Answers
Make an animation play over RPC call? 1 Answer
Network FPS Scripting Help 1 Answer