I have a client server build in Unity 5. I want to send a command from the client to the server with a GUI button click, this is for testing purposes. So on my client all I want is to click a button and then have the server display a message on its console window. Reading through http://docs.unity3d.com/Manual/UNetActions.html this seems to require a player object. With the demo I am trying to create there is no player. So I created an empty game object and called it player and assigned it a player script:
public class Player : NetworkBehaviour {
void Update ()
{ //receive message from camera follow script to run command from client to server
if (isServer)
return;
if (GameObject.Find("Main Camera").GetComponent<CameraFollow>().sendCommand)
{
CmdTurnOnNetworkTransformOnServer ();
}
}
[Command]
void CmdTurnOnNetworkTransformOnServer()
{
UnityEngine.Debug.Log ("Received");
}
}
This script checks if a boolean is true on another script (the script that contains the GUI button that when clicked sets the bool to true). if it is true then I would like the server to display "Received" on the console in the editor. However I get the error "Trying to send command for non-local player." From what I can see I am following the above link properly to just display a simple message. I realise there is another route with http://docs.unity3d.com/Manual/UNetMessages.html however I would like to see if I can get a command working instead.
Full Error: Trying to send command for non-local player. UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String) Player:CallCmdTurnOnNetworkTransformOnServer() Player:Update() (at Assets/Player.cs:37)
How come I am getting this error?
This error appears in the client console window