Unity Multiplayer Send Message to Specific Client

Hello. I am trying to make a multiplayer card game. For that, I believe I need to send messages to the individual clients whenever there’s an action. Such as when the game starts, each player will have their board with different orientations because both of them have their “base” on the bottom.

I already tried registering a handler and using the connectionToClient.Send() method, but it does not work for some reason.

    class SpawnMsg : MessageBase { }
    public override void OnServerAddPlayer(NetworkConnection conn, short id) {
        base.OnServerAddPlayer (conn, id);
 
        playerNumber++;
        conn.RegisterHandler (MsgSpawn, gameManager.SpawnObjectMessage);
        conn.Send (MsgSpawn, new SpawnMsg());
    }


//different class
   public void SpawnObjectMessage(NetworkMessage msg) {
        Debug.Log ("MESSAGE RECEIVED");
    }

I figured out a solution, though I am not sure it is the best method.

    public override void OnStartLocalPlayer() {
        base.OnStartLocalPlayer();    
        CmdReady(CustomNetworkManager.localPlayerUsername);
    }

    [Command]
    void CmdReady(string username) {    
        if (CustomNetworkManager.player1 == null) {
            CustomNetworkManager.player1 = this;
            this.username = username;
        } else if (CustomNetworkManager.player2 == null) {
            CustomNetworkManager.player2 = this;
            this.username = username;
            RpcReady(username);
        }
    }

This way, when RpcReady is called, both users already connected and the server knows their username. Also, username is a syncvar.

[SyncVar(hook = "OnUsernameChange")]
    public string username;

And when RpcReady is called, it will be called on the second player, so you can follow the same pattern to notify the client and server of each different player.

Well, sorry if it’s hard for me to explain. But the main thing is, first understand how these Commands and Rpc calls work, then just juggle them.