Turn Based Random ActorNumber ID

Options

Good day!

I have a chess game with PUN. My question is that whenever the one who creates the room first usually is the first to move (white player). And the one to join is the black player.

I was hoping that creating a room and joining would randomize who is white and black and not by the one who creates and joins.


myClientID = PhotonNetwork.LocalPlayer.ActorNumber;
myPlayer = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity);
myPlayer.GetComponent<Player>().myId = myClientID;

that is the code above being used. It might not be the best practice. please help on how to have a randomize player id. Or if there is another best practice approach please let me know. Thank you in advance.

Answers

  • Tobias
    Options

    You could possibly run a random number generator on the first player's client. Generate 0 or 1 and depending on this result, your player 1 should pass the first turn to whoever joins.

    You can sync a property who started the game (as 0 or 1, e.g.) in the Custom Room Properties.