Simple UNET issue - 2 player game, let opponent 'hear' a button press

Creating a 2 player turn based board game with UNET. More precisely using the NetworkLobby asset Unity Engine - Unity Discussions

Stumbling over something which should be so simple.
When the local player presses a button, I need the remote (opponent) player to ‘hear’ the button press.

and vice versa of course.

I’m trying the usual [Command] plus [ClientRpc] methods and there is communication happening but can’t figure out how to determine if a receiving event is from the remote or local player.

Can any UNET experts help?

Also just to clarify
a [Command] originates on a Client but is executed on the Server. There is only 1 at a time.
and
a [ClientRpc] method originates from the Server but executes on the Client(s). There are as many as there are Clients or players.

Am i correct?

You can also use TargetRpc to only send it to one specific player

Thanks, wasn’t aware of that. But with TargetRPC how do you determine the NetworkConnection object?

Also figure that since its only a 2 player game might be easier for me to use the default ClientRpc and then do a check for isLocalPlayer.

@eco_bach

You can override OnServerAddPlayer() in a custom network manager script and assign the network connection to a list of “active players” on your server.

using UnityEngine;
using UnityEngine.Networking;

public class NetworkManager_Custom : NetworkManager
{
    public MatchManager matchMan;

    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    {
        Debug.Log("OnServerAddPlayer()...");
        //Add Player to the active player list.
        matchMan.activePlayers.Add(conn);
    }
}

MatchManager has a list that the server can use as a reference to the player.
Hope that helps.