RPC Client and Server playing

Hi everyone,

I am implementing a multiplayer game and I am using Networkview.RPC() to make my calls.

The game should have two players.

I think I am a bit confuse about who’s the server and the client. Here’s what I have:

  • Master Server hosted in Digital Ocean
  • My Code to create room with MasterServer.RegisterHost()
  • Code to find match and connect

All this works (I am not sure if it works as should)

My question is:

Should the server be the player also?
because when one person on his phone creates the match, he will be the server…
the person who connected to the created game will be the client…

my RPC is sent to all, like so:

networkView.RPC("doMove", RPCMode.All, null);

when the server do the movement, I can see it being updated in the other phone (the client)…
but the opposite doesn’t work… when I do the movement with the client it doesn’t update the server.

Can someone explain me if I really understood this game logic between the server and client and what is wrong?

Any help will be very appreciated.
Thanks.

You are using obsolete functions. Unet is actually pretty good once you get used to it. I will try to give a quick overview of UNet if you wish to try to use it.

[Command] //this lets a client call code on the server's copy of the object that the script is attached to as long as it has local authority to the client... code called in the function will be called on the server's object only MUST be named with Cmd..
example:
[Command]
void CmdmyFunction()   //maximum of one parameter that must either be a native type or a      struct/class of native types 

[ClientRpc]  //this lets a server call code on the client... code called in this function will be run on the client MUST be named with Rpc
example:
[ClientRpc] 
void RpcmyFunction2()   //maximum of one parameter that must either be a native type or a     struct/class of native types 

[Server] //code will only execute on the server it will NOT EXECUTE if you call the function on the client
example:
[Server]
void serverOnlyFunction()

[Client] //code will only execute on clients it will NOT EXECUTE if it is called on the server.
example:
[Client]
void clientOnlyFunction()

class myClass : NetworkBehaviour
{
    [SyncVar] //only usable on native types will automatically sync from server to client
    int health;
}

you may use isServer and isLocalPlayer to determine what you are. Note that since you are hosting the server and also playing on that that both of these will return true on the hosting phone. Hopefully this will help you if no one responds to the old code which I don’t know well enough unfortunately.