I’m working on a Unity 2D multiplayer game using UNet. My problem is that the Client cant send the [Command] to the server. Im debugging on UnityEditor and a built apk for my android phone.
First I used UnityEditor as Host and the phone as Client, the Debug.Log(SkinName) APPEARS on the console.
Then I used UnityEditor as the Client and the phone as Host, the Debug.Log(SkinName) DOES NOT APPEAR.
I tried to use [ClientRpc] instead of [Client] but it just made it worse, both client and host wont sync.
I’ve visited other threads/forums and other UNet tutorials to look for solutions but this is what I came up with.
Note: On the other threads that I visited, people mostly suggest that Local Player Authority is unchecked and that is what causing the problem but in this case it is CHECKED.
Code:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using Spine;
using Spine.Unity;
using Spine.Unity.Modules;
class SetupLocalPLayer : NetworkBehaviour {
[SyncVar]
public string SkinName;
public string[] CharNames;
public string[] SlotNames;
public string[] AttachmentSuffix;
void Start (){
TransmitSkins ();
SyncSkin ();
if (isLocalPlayer) {
var skeletonrenderer = GetComponent<SkeletonRenderer>();
for(int z=0;z<SlotNames.Length;z++){
skeletonrenderer.skeleton.SetAttachment(SlotNames[z],GameController.control.skinName+AttachmentSuffix[z]);
}
GetComponent<PlayerManager> ().enabled = true;
GetComponent<FollowCam> ().enabled = true;
}
}
void Update () {
}
void SyncSkin(){
if (!isLocalPlayer) {
var skeletonrenderer = GetComponent<SkeletonRenderer>();
for(int z=0;z<SlotNames.Length;z++){
skeletonrenderer.skeleton.SetAttachment(SlotNames[z],SkinName+AttachmentSuffix[z]);
}
}
}
[Command]
void CmdSetSkin(){
SkinName = GameController.control.skinName;
Debug.Log (SkinName);
}
[Client]
void TransmitSkins(){
if (isLocalPlayer) {
CmdSetSkin ();
}
}
}