Question by
kanaron · Sep 25, 2016 at 05:38 PM ·
networkingcommand
How to call [Command] from client?
I have problem wich [Command] functions: they call from host, but not from client.
I wrote script to sync rotation of object and I assing it to player object with Network Transform and Network Identity. I sync rotation of one child of player object. Script:
public class MSync : NetworkBehaviour {
public Transform RotSyncObj;
[SyncVar]
Quaternion ObjRot;
[Command]
void CmdRotateToServer (Quaternion rot)
{
RotSyncObj.rotation = rot;
Debug.Log("CmdRotate");
}
void transmit()
{
if (isLocalPlayer)
{
ObjRot = RotSyncObj.rotation;
CmdRotateToServer(ObjRot);
Debug.Log("Transmit " + gameObject.GetComponent<NetworkIdentity>().netId);
}
}
void Update()
{
transmit();
}
}
If I play as host in console I got both Debug.Log() messages. But if I play as client I got only message from transmit() function. Command not working on client.
And when I rotate host's object I can see it on client. But when I rotate client's object I can't see it on host.
So why [Command] not working on client?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612093455im_/https://answers.unity.com/themes/thub/images/avi.jpg)