I know this is probably a "nooby" question, but I haven't worked that much with networking before so I find it a bit difficult to understand.
Here's an AnimationSynchronizer script that was included with Unity3d SFS island demo:
Code: Select all
using UnityEngine;
using System.Collections;
using System;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
public class AnimationSynchronizer : MonoBehaviour {
private bool sendMode = false;
private bool receiveMode = false;
private string lastState = "idle111";
// We call it on local player to start sending animation messages
void StartSending() {
sendMode = true;
receiveMode = false;
}
// We call it on remote player model to start receiving animation messages
void StartReceiving() {
sendMode = false;
receiveMode = true;
animation.Play(lastState);
}
void PlayAnimation(string message) {
if (sendMode) {
//if the new state differs, send animation message to other clients
if (lastState!=message) {
lastState = message;
SendAnimationMessage(message);
}
}
else if (receiveMode) {
// Just play this animation
animation.CrossFade(message);
}
}
void SendAnimationMessage(string message) {
SmartFoxClient client = NetworkController.GetClient();
SFSObject data = new SFSObject();
data.Put("_cmd", "a"); //We put _cmd = "a" here to know that this object contains animation message
data.Put("mes", message);
client.SendObject(data);
}
}
Now I want to add more animations, for e.g. punch animation when player clicks mouse button or jump animation when player presses Space.
How do I do that? Could anyone please give me a very basic example of how to add more animations to this Animation Synchronizer script?
It's really unclear how to do that in the island demo, so I'm seeking for a simplest example of what to add to this script for example for "jump" animation to be played when Space is pressed.
(I know how to do it for local player but not for remote >.<)
Thanks in advance.