How to make a Character Selection

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 :smile:

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 )

Did you try calling it in a Command? Just an idea…

There are multiple solutions for this.
*store the color as a variable and mark it with sync var, this will ensure everyone gets the same value.
*let the player choose the color from start, and spawn it with the color pre-set.
*use commands/RPC/messages to broadcast the color.

Dunno if this helps you but I developed and used this, which is attached to the object.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class Object_SyncColor : NetworkBehaviour {

    [SyncVar (hook = "OnColorChange")] Color newColor;
    private Color currentColor;


    void OnColorChange(Color _myColor) {

        gameObject.GetComponent<Renderer> ().material.color = _myColor;
        currentColor = _myColor;

    }

    void Update () {

        if (!isLocalPlayer)
            return;

        if (currentColor != gameObject.GetComponent<Renderer> ().material.color) {
            Cmd_DoColor (gameObject.GetComponent<Renderer> ().material.color);
        }
    }

    [Command]
    void Cmd_DoColor(Color _theColor) {
        newColor = _theColor;
    }
}