I’m trying to create a simple character selection option, but i can’t figure it out how to make the server and all the clients to have the same character options the player choosed.
So, here’s my character instiation:
public void OnServerAddPlayer(NetworkConnection p_conn, short p_playerControllerId)
{
GameObject player = (GameObject)Instantiate(playerPrefab, playerSpawnPositions[p_conn.connectionId].position, Quaternion.identity);
NetworkServer.AddPlayerForConnection(p_conn, player, p_playerControllerId);
}
After that this happens, the code bellow show two buttons that give the option to the player to choose the character Sprite Collor.
private void OnClientConnect(UnityEngine.Networking.NetworkConnection p_conn)
{
guiManager.ShowMenu(GUIManager.MenusIndex.CHOOSE_CHARACTER, true, null);
}
After the player have pressed one of the buttons, the method bellow will be called. How do i make so that this method is executed on the server and all the clients, so that everyone can see witch Collor my own character is and the others players characters is ?
Ps. Sorry, for my english, making my best here with google translate ![]()
public void OnCharacterRequested(byte p_characterId)
{
Debug.Log("Requesting character...");
switch(p_characterId)
{
case 0:
thisPlayer.nickName = "P0";
thisPlayer.spriteRender.color = Color.blue;
break;
case 1:
thisPlayer.spriteRender.color = Color.green;
thisPlayer.nickName = "P1";
break;
}
thisPlayer.spriteRender.enabled = true;
}
As you can see on the image bellow the Collor changes only for you, the other other players see the default color ( White )
