- Home /
Command/ClientRpc/ Help -- Need Client Commands to run!,Question About Command/ClientRpc/Client Authority
Disclaimer: I am rather new to Unity and I may be going about this the wrong way -- if you feel or think so, please tell me and help me get out of my rabbit hole!
My issue is a simple one - but I think the way we are doing things in our game is a little bit different than what I've usually been seeing in tutorials/answers. Usually I see advice to spawn new players, however we have opted to simply set the two player objects with the proper authority, as our Players have UI/Visual elements we need from scene to scene set on them. We realize now that that is probably very bad practice, and are working on reformatting our player code to only handle actual game logic inside - rather than visual elements.
We have a two player game that we've been porting to multiplayer. We would like your player to always be on the left, theirs on the right, and for that to be equally true if you are a client vs the host player.
We have a GameStateManager script that had DontDestroyOnLoad attached, and two players. The network manager script is attached to our GSM, and we have a modified network behaviour script on either player. They are both set to LocalPlayerAuthority = true.
This is how we add the players to the network:
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
GameObject player;
short playerId;
if (conn.address == "localClient")
{
playerId = 0;
player = GameStateManager.instance.player_1.gameObject;
GameStateManager.instance.player_1.IsMainPlayer = true;
}
else
{
player = GameStateManager.instance.player_2.gameObject;
playerId = 1;
}
NetworkServer.AddPlayerForConnection(conn, player, playerId);
}
This is how we set LocalPlayer authority:
public override void OnStartLocalPlayer()
{
//base.OnStartLocalPlayer(); // I am unsure I need/want this.
Player = GameStateManager.instance.OurPlayer;
if (playerControllerId == 1)
{
ChangeGameStateFilter(GameStatus.MonsterSelection);
}
}
And this is the general pattern of how we run our functions:
public void Example()
{
if(isServer)
{
RpcExample();
}
else
{
CmdExample();
}
}
[Command]
public void CmdExample()
{
RpcExample();
}
[ClientRpc]
public void RpcExample()
{
// For example, add a monster to our player
// This is our clients player object, we use TheirPlayer to refer to the other player
Player = GameStateManager.instance.OurPlayer;
Player.AddSelectedMonster();
}
THe problem seems to be that no matter what I do, whenever I select a monster to choose a monster, it only gives it to the host player. I would like to click the monster on the correct screen and add it to our players monsters.
I know this is a somewhat open-ended question - mainly looking for advice/best practice direction so I can help drag our game out of the current miasma it's stuck in. If I can offer any more information or answer anything, please let me know.
Extra Credit -- If my players both have local authority and are set to islocalplayer correctly, do I need the base.OnStartLocalPlayer()? ,
Your answer
Follow this Question
Related Questions
What to do when user clicks back on google play games realtime multiplayer auto-match ui ? 0 Answers
Photon network won't join random room with a custom property 0 Answers
UNET Networking: Changing Players texture 0 Answers
Photon RPC is not working in photon? 2 Answers
How do I create a multiplayer turnbased game server? 0 Answers