How can I pass rgb color to OnPhotonSerializeView
Options
JustCore
✭
I need to pass rgb variables to OnPhotonSerializeView.
I tried to do it like this:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(healthCircle.color.r); stream.SendNext(healthCircle.color.g); stream.SendNext(healthCircle.color.b); } else { healthCircle.color.r = (float)stream.ReceiveNext(); healthCircle.color.g = (float)stream.ReceiveNext(); healthCircle.color.b = (float)stream.ReceiveNext(); } }
After this i get an error:
Assets\Scripts\Player.cs(68,13): error CS1612: Cannot modify the return value of 'SpriteRenderer.color' because it is not a variable
I tried to search it in google but i didn't find anything. Sorry for my noob question. Waiting for your help :)
0
Answers
-
hey! this is cause u cant modify properties of structs since structs r value types (heres a post that explains why that is)
what ud wanna do instead for reading ur rgb values would b smth like:
Color healthColor = new Color(); healthColor.r = (float)stream.ReceiveNext(); healthColor.g = (float)stream.ReceiveNext(); healthColor.b = (float)stream.ReceiveNext(); healthCircle.color = healthColor;
hope this helps :)
0