Multiplayer problem

Hi,

I make a multiplayer tank fighting game with the new Unity5 network features. In general my multiplayer setup is working now. I have the problem, that I see my host shoots and detonations in both, client and host, but not the client shoots and detonations. This are only visible on the client side.

alt text

I know I have to sync it, but the documentation not really complete yet and I don’t know when to use [ClientBehavior] [Command] and [Syncvar]

I would be happy about a little help. Thanks.
Frank

You need to do almost everything on the server. Although a client or human player might decide to shoot, it’s the decision that happens on the client, not the actual firing. The client commands the server to do it. You can use the Command for this, eg:

    [Client] // runs only on client
    public void Shoot(Vector3 target)
    {
        CmdShoot(target, identity);
    }

    [Command] // runs only on server
    private void CmdShoot(Vector3 target)
    {
        var obj = (GameObject)Instantiate(TankShellPrefab, MyTranform, someRotation);
        NetworkServer.Spawn(obj);
        // etc
        RpcTankEventHappened("shot");
    }

    [ClientRpc] // runs only on client
    public void RpcTankEventHappened(string something)
    {
        if (something.Equals("shot")) {
          // decrease on-screen ammo count
        }
    }

Note that for this to work you need be in a NetworkBehavior, and have the NetworkIdentity and NetworkTransform on the Prefab, but I think you have these already.

See the docs for the ClientRPC call for more details of server → client high-level messaging, for informing the client that something’s happened (like damage).