- Home /
Photon Player Property failing to update?
Right now, I'm trying to use player properties to set the color of my character. I have a series of 8 buttons with different colors, and if I click one, that's the color my character becomes. \
private void SetCustomCharacter(string newCharacterName)
{
Hashtable playerProps = new Hashtable();
playerProps.Add("character", newCharacterName);
PhotonNetwork.LocalPlayer.SetCustomProperties(playerProps);
}
But the colors always seem to be one behind. When I click a button (say "Blue"), my character has null color, then if I click "Yellow", my character turns blue, and click green, turn yellow and so on... Why is this happening? I'm fairly new to photon, so I'm not too sure what's happening.
I've tried using OnPlayerPropertiesUpdated but that never ever gets called. Please help.
Also, my code for setting colors (I have this as an RPC to the color for all characters):
[PunRPC]
private void SetColor()
{
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject playerModel in players)
{
foreach (Player player in PhotonNetwork.PlayerList)
{
if (playerModel.GetComponent<PlayerControl>().GetPlayerID() == player.ActorNumber)
{
string color = (string) player.CustomProperties["character"];
playerModel.GetComponent<Renderer>().material = Resources.Load<Material>("Materials/" + color);
}
}
}
}
Comment
Your answer
