Photon pun 2 tell all players present in room to execute a function

Hello,

I am trying to create a multiplayer snake game using Photon Pun 2. i have a multiplayer manager script, now i want to start the game only after 2 players have joined sending a message to all the players present that they can move now. how would i achive this? here is my multiplayer manager code which checks for players, its being invoked every second:

void CheckNumberOfPlayers()
    {
        if (twoPlayersPresent == false)
        {
            if (PhotonNetwork.CurrentRoom.PlayerCount == 2)
            {
                twoPlayersPresent = true;
                view.RPC("EnableSnakeController", RpcTarget.AllViaServer);
                plsWait.gameObject.SetActive(false);
            }
            else
            {
                plsWait.text = "Please wait for players to join";
            }
        }
        else
        {
            return;
        }
    }

i have an rpc funtion inside the snake script which enables the movement.

Use the callback OnPlayerEnteredRoom(). In it, let the Master Client start the match…

No, my doubt is that how do i send a message to both the players that should tell them to execute a function inside their script?

this is inside my snake script:

[PunRPC] void EnableSnakeController()
    {
        canMove = true;
        //PhotonNetwork.Destroy(gameObject);
    }

the function view.RPC("EnableSnakeController", RpcTarget.AllViaServer); should execute the code above which is inside the snake script.

Is the question how to send this? Or is it “how to execute some code when the full player count is reached”?

Because the latter question is answered by using OnJoinedRoom() and OnPlayerEnteredRoom(). Whenever OnJoinedRoom() is being called, check if the player count is 2. If it is: start. Is it not, the client has to wait for someone else to join. PUN then calls OnPlayerEnteredRoom() when someone else joins, so then the player count should be two and … you can execute that code directly. No need to signal this via RPC. It’s just … fluff.

Yes, it should. On one networked object. The one that has this particular view component. Every other controller that waits to wake up won’t. Because RPCs target a specific networked object / view.