Sync materials between players?

Options

Is it possible to sync materials between players? like, when a player changes color during the game, I want the other players to be able to see that. Maybe something to do with RPCs? If so, could someone please point me in the right direction?

Best Answers

  • dcmrobin
    dcmrobin
    Answer ✓
    Options

    I've now changed the MonoBehaviour to MonoBehaviourPunCallbacks and added this bit of script:

    public override void OnPlayerEnteredRoom(Player newPlayer)

        {

            base.OnPlayerEnteredRoom(newPlayer);

            pv.RPC("UpdatePlayerColor", RpcTarget.All);

        }


    and now I can detect when a player enters the room!

  • Tobias
    Tobias admin
    Answer ✓
    Options

Answers

  • dcmrobin
    Options

    Ah, I've partially figured it out. When the player spawns, it sends an RPC to every player in the room. This almost works, but here's the problem. A player enters the room. He sends an RPC to everyone in the room, but there aren't any players in the room. Another player joins. He sends an RPC, and the first player gets it and can observe the second player's color! But since the first player's RPC was wasted on "thin air" so to speak, the second player cannot observe the first player's color. I tried just putting an RPC call in the update loop so that every player is sending an RPC, to everyone, all at once, forever. This kind of worked, but as you can probably imagine, it slowed the game down. Now, the thing I want to know is if there's a way to detect when a player enters the room, so that the players only send RPCs when that happens, not in the update loop. I've seen OnPlayerEnteredRoom but that's for Photon Realtime, right? Is there a Photon PUN version of this?

  • dcmrobin
    dcmrobin
    Answer ✓
    Options

    I've now changed the MonoBehaviour to MonoBehaviourPunCallbacks and added this bit of script:

    public override void OnPlayerEnteredRoom(Player newPlayer)

        {

            base.OnPlayerEnteredRoom(newPlayer);

            pv.RPC("UpdatePlayerColor", RpcTarget.All);

        }


    and now I can detect when a player enters the room!

  • Tobias
    Options

    Why the RPC. Everyone knows the player entered and you don't pass a variable (yet?!) to the RPC. You can just update the color.

  • dcmrobin
    Options

    What do you mean? That was the problem: updating the color didn't sync.

  • Tobias
    Tobias admin
    Answer ✓
    Options
  • dcmrobin
    Options

    I've got it working, thanks for your help!