I want to create a simple demo. I want there to be a cube, in the middle of a plane, that changes colors when you click it. (This was easy to implement) I want there to be two players, who take turns clicking the cube. The cube will only change colors if it is your turn. If the cube changes colors, the change will reflect on both the players' screens. I've been looking at the examples for UNET, http://forum.unity3d.com/threads/unet-sample-projects.331978/, and most of them have a networked character who you control with your keyboard, and this aspect is throwing me off. Do I still need to create 2 players, but just have them be invisible and have no control scripts? Should my block be a prefab? Here's my script for my block:
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
// Command function is called from the client, but invoked on the server
CmdChangeColor();
}
}
[Command]
void CmdChangeColor()
{
if (cubeColor == Color.green) cubeColor = Color.magenta;
else if (cubeColor == Color.magenta) cubeColor = Color.blue;
else if (cubeColor == Color.blue) cubeColor = Color.yellow;
else if (cubeColor == Color.yellow) cubeColor = Color.red;
else cubeColor = Color.green;
GetComponent<Renderer>().material.color = cubeColor;
}
Also I'll note that my Block isn't currently a prefab. I have the Network Identity component enabled, as well as the network transform->Sync transform. When I start the server host, I'm able to change the color of the block, but the client can't view these changes. When the client clicks the block, nothing happens, except the error message: Trying to send command to the object without authority.
Any help would be appreciated! Thank you http://docs.unity3d.com/Manual/UNetSetup.html