Building a co-op story game

I’ve been trying to figure out my way through UNET to try and build a co-op game (similar to oldschool Resident Evil or Silent Hill) where there’s buttons and items all throughout that both players would have the ability to pick up and do things with.

So far, I’ve got a button that only the Host can press. If the client presses it, I get a “RPC function called on client” error. The code I have for this is (all this is supposed to do is play a sound on both instances):

  • [Command]
  • private void CmdInteract()
  • {
  • RpcInteract();
  • }
    • [ClientRpc]
  • private void RpcInteract()
  • {
  • GetComponent().PlayOneShot(GetComponent().clip);
  • }

So what I’m doing is calling CmdInteract from the Character Controller script, which I believe is supposed to only be ran on the server, which sends out the RPC to both clients which plays the sound. Again, if the Host presses the button it works, but I get that error if the client attempts to.

I’d think I’m doing something fundamentally wrong, but I’m not sure exactly what way I’m supposed to be doing something like this.

On a separate note, I have tried this another way and have found that the client can’t press it again because it doesn’t have authority over the object (although the Host does). Is there any way you can have an object with two players having authority over it?

Client can only call commands on object he owns. So you can make two invisible objects each belonging to corresponding player affecting that single common object you need both players to modify.