Question by
Sakurazaki · Jun 04, 2016 at 11:54 PM ·
errorgamerpcclient-servercommand
How to update player from another player in Local Player Authority
Hi.
I'm trying to do a simple Sink the Fleet game in Unity to learn and begin using Networking with Unity and Unity itself.
This is my Player prefab
public class Player : NetworkBehaviour {
[SyncVar]
public SyncListInt field = new SyncListInt();
void Start() {
for (int x = 0; x < 100; x++)
{
field.Add(0);
}
}
public void doClick(int x, int value) {
if (!isServer)
{
CmdClick(x, value);
}
else {
field[x] = value;
// Because its SyncVar this shouldnt be necessary
RpcClick(x, value);
}
}
[ClientRpc]
void RpcClick(int x, int value) {
// Because its SyncVar this shouldnt be necessary
Debug.Log(x + " " + value);
}
[Command]
void CmdClick(int x, int value)
{
field[x] = value;
// Because its SyncVar this shouldnt be necessary
RpcClick(x, value);
}
}
My understanding so far is this: - In the host I can update players and because these are SyncVar whatever I do in here its replicated to all clients. This works fine. - In the client, when I click on the field I call CmdClick to update the Player in the server and because its SyncVar its replicated in all clients. This does not work.
When I click in any of the field squares with the client the change never makes to the server. I'd like to know what I'm doing wrong or maybe another way to approach what I need to do.
Thank you.
Comment