I have been able to get a cube to change color, but it is not showing over the network.
I put a photon view on the cube, and then had it observe the following script, which I also placed on the cube:
void Update() {
if (Input.GetKeyDown(KeyCode.P)){
gameObject.renderer.material.color = Color.magenta;
}
if (Input.GetKeyDown(KeyCode.B)){
gameObject.renderer.material.color = Color.cyan;
}
}
it then tells me to use a photonserializeview, so I tried somehting like this:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
if(stream.isWriting){
//send color
}
else{
//get color
}
but I have no idea what needs to be done next. Am I on the right track? Thanks
If the color does not change all that often, you can also use a player “Custom Property” to store the player’s color (skin, tools, etc). If you don’t send anything else, the use of OnPhotonSerializeView() is not the best option.
The PhotonPlayer class has SetCustomProperties(Hashtable propertiesToSet). The key can be any string (e.g. “c” because that’s shorter than “Color”) and the value can be either the Vector3 or an integer (leaner). Set your color in a room via PhotonNetwork.player and get everyone’s color by going through the player list PhotonNetwork.playerList (which includes the local player).