Hello. I need some help with multiplayer. I have purchased the new multiplayer course and so far everything works as it is suppose to(I have completed the first section to the combat polish) but I don’t understand the material very well.
This is my first attempt with multiplayer and I am having trouble understanding the client vs server actions. I am trying to reinforce the learnings by applying to my own project. What I’d like to do is have a loot box. If the client interacts with it I need the box sprite to change to an open state and have that by synced on the host and clients. Then I want to spawn objects about the box for the players to pick up.
What I have tried so far is to subscribe to the OnDie action so that the player can shoot the loot box and “Kill” the box and that will trigger the following
sudo
subscribe to OnDie += BreakOpen
(BreakOpen)
OpenChestServerRpc
OpenChestClientRpc
(OpenChestServerRpc)
Instantiate loot
update sprite
(OpenChestClientRpc)
update sprite
This seems to work ok but not sure if this is the correct way or is there is a better way. Also I’d like to have the open to have the player walk up and interact with the loot box. This is where I get lost. I am not sure the best way to let the server know. I tried the following
Sudo Code
Button Press to interact triggers (Open)
(Open)
OpenChestServerRpc
(OpenChestServerRpc)
spawnloot
update sprite
When I do this interacting on the host seems to work fine triggering the host update and the client but if I interact with the client there is no update on either.
Any help would be greatly appreciated. Or pointing to some material. I have looked at the unity docs and codemokey multiplayer tutorial as well. Still confused.