- Home /
 
How to call [Command] on Client in UNet
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 ();
     }
 }
 }
 
              Answer by pseudowok · Oct 20, 2016 at 03:23 PM
It looks to me like you are sending the Debug.Log as a command to the server, so it wouldn't run on the client. If you wanted it to run on the client you would have to do something like:
 [Command]
 void CmdSetSkin(){
 SkinName = GameController.control.skinName;
 RpcSkinName(SkinName);
 }
 
 [ClientRpc]
 void RpcSkinName(String skinName){
 Debug.Log(skinName);
 }
 
              Your answer