Best practice for calling a function over multiplayer

Options
So quite a simple question I hope but what is the best method of calling a function over multiplayer from another object?

For example I have a button which opens a door, should the script on the button read?
Door.GetComponent<PhotonView> ().RPC ("OpenDoor", PhotonTargets.AllBuffered);

Or should the network code be on the OpenDoor function instead which calls its self over the network?
public void OpenDoor() {
    GetComponent<Animator>().opendoor etc;
    if(GetComponent<PhotonView>().isMine)
    {
        GetComponent<PhotonView> ().RPC ("OpenDoor", PhotonTargets.OthersBuffered);
    }
}
Many thanks
Rob

Comments

  • Hi @HeskethGames,

    I think it doesn't make a big difference if you use the first or the second option. The second option might be better readable than the other one though. If you the second option please make sure that your RPC function differs from the function that calls the RPC and that you add [PunRPC] attribute, for example OpenDoor() and OpenDoorRpc().