devNotes 4-02-16 networking netMove states – Cmd from client

instantiate remote_paint and link to Argos Remote.

pass color & width

Update Remote Cursor

Clear Local / All

NetworkAuthority

 

NetworkLocalPlayers

RPC

Commands are run on the player object on the server that corresponds to the client that sent the command. This routing happens automatically, so it is impossible for a client to send a command for a different player.

Commands must begin with the prefix “Cmd” and have the [Command] custom attribute on them, like below:

using UnityEngine;
using UnityEngine.Networking;
 
public class ArgosObj : NetworkBehaviour
{
    bool bDrawing;
    float markVal;
    int spin;
 
    [Command]
    public void CmdMark(float markVal, int spin)
    {   
        if (!bDrawing)
        {
            this.markVal= 0;
            this.spin = 0;
            return;
        }
            
        this.markVal = markVal;
        this.spin = spin;
    }
 
    [ClientCallback]
    void Update()
    {
        int spin = 0;
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            spin += 1;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            spin -= 1;
        }
        // this will be called on the server
        CmdMark(Input.GetAxis("Vertical"), spin);
    }
}