- Home /
sync animations problem
Hello!
I am making a multiplayer game and I'm using the networkingSyncAnimation.cs script to synch my animations. I have made a script anim.js that sends the states of animations, which is this: animation.wrapMode = WrapMode.Loop;
animation["jump"].wrapMode = WrapMode.Clamp; animation["walk"].wrapMode = WrapMode.Clamp;
animation["idle"].layer = -2; animation["walk"].layer = -2; animation["excited"].layer = -1; animation["look"].layer = -1; animation["think"].layer = -1;
animation.Stop();
function Update () { if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.0) { animation.wrapMode = WrapMode.Loop; animation.CrossFade("walk"); SendMessage("SyncAnimation", "walk"); }
else
{ animation.Play("idle");
animation.CrossFade("idle");
SendMessage("SyncAnimation", "idle");
}
if (Input.GetButtonDown ("Jump"))
{ animation.wrapMode = WrapMode.Once;
animation.CrossFade("jump");
SendMessage("SyncAnimation", "jump");
}
}
function Excited() {
animation.wrapMode = WrapMode.Once;
animation.CrossFade("excited");
SendMessage("SyncAnimation", "excited");
}
function Think(){ animation.wrapMode = WrapMode.Once; animation.CrossFade("think"); SendMessage("SyncAnimation", "think");
}
function Look(){ animation.wrapMode = WrapMode.Once; animation.CrossFade("look"); SendMessage("SyncAnimation", "look"); }
And it works great. The three functions excited,think and look are called when gui buttons are pressed. Then I use the networkingSyncAnimation.cs for synching the animations. I changed it a little bit and now it looks like this
using UnityEngine;
using System.Collections; using System;
public class NetworkSyncAnimation : MonoBehaviour {
public enum AniStates
{
walk = 0,
idle,
jump,
think,
excited,
look
}
public AniStates currentAnimation = AniStates.idle;
public AniStates lastAnimation = AniStates.idle;
public void SyncAnimation(String animationValue)
{
currentAnimation = (AniStates)Enum.Parse(typeof(AniStates), animationValue);
}
// Update is called once per frame
void Update () {
if (lastAnimation != currentAnimation)
{
lastAnimation = currentAnimation;
animation.CrossFade(Enum.GetName(typeof(AniStates), currentAnimation));
animation["walk"].normalizedSpeed = 1.0F;
}
}
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting)
{
char ani = (char)currentAnimation;
stream.Serialize(ref ani);
}
else
{
char ani = (char)0;
stream.Serialize(ref ani);
currentAnimation = (AniStates)ani;
}
}
}
My problem is that only the walk and idle movements sync and the others don't. Any ideas why happens this? In my anim script I even divided the animations in layers, so the three animations that don't play have a priority. Any help would be highly appreciated. Thanks!
Answer by gooncorp · Mar 05, 2012 at 12:12 AM
shouldnt there be another line near:
animation["walk"].normalizedSpeed = 1.0F;
Your answer
![](https://koobas.hobune.stream/wayback/20220612124241im_/https://answers.unity.com/themes/thub/images/avi.jpg)