Adjust color of player prefab using SetCustomProperties

Options
FGStud
FGStud
Can someone help me out? Not sure why this isn't working.

I'm trying to set each player to the color that the local player picks from a color wheel. The pick color before the session starts.

I store the local player's choosen color in PlayerPrefs.

PlayerPrefs.SetFloat("bodyColorR", ColorPickerToUse.value.r); PlayerPrefs.SetFloat("bodyColorG", ColorPickerToUse.value.g); PlayerPrefs.SetFloat("bodyColorB", ColorPickerToUse.value.b); PlayerPrefs.Save();

When player joins room I create hashtable with local body colors choosen and stored in PlayerPrefs.

void OnJoinedRoom() { Debug.Log("room joined"); ExitGames.Client.Photon.Hashtable style = new ExitGames.Client.Photon.Hashtable(); style.Add("bodyColorR", PlayerPrefs.GetFloat("bodyColorR")); style.Add("bodyColorG", PlayerPrefs.GetFloat("bodyColorG")); style.Add("bodyColorB", PlayerPrefs.GetFloat("bodyColorB")); PhotonNetwork.player.SetCustomProperties(style); CreatePlayerObject(); }

Once player is spawned into room I set the color (choosen locally) of player in the start of network script attached to prefab.

void Start () { m_PhotonView = GetComponent<PhotonView> (); float playerColorR = (float) PhotonNetwork.player.customProperties["bodyColorR"]; float playerColorG = (float) PhotonNetwork.player.customProperties["bodyColorG"]; float playerColorB = (float) PhotonNetwork.player.customProperties["bodyColorB"]; skinnnedMeshRendPlayer.material.EnableKeyword ("_Color"); skinnnedMeshRendPlayer.material.SetColor("_Color", (new Color(playerColorR, playerColorG, playerColorB, 1))); }

This is wrong!

This results in all players in the room having the same color. The color that all players have is the color the local player choose.

I need each player to have their own distinct choosen color.

Do I have to do anything else to distinguish local player from remote player via SetCustomProperties?

Does my code seem correct?



Comments

  • vadim
    Options
    In Start() you always use properties of local player PhotonNetwork.player
    You need to access properties of object owner instead. Try photonView.owner.customProperties
  • FGStud
    Options
    Works perfect now. Thank you