Okay, so all I simply need is to convert float (e.g 3.422
) and turn it into a byte[]
.
I need this because I am sending the byte as data for real time multiplayer. Everywhere I look online just have really complicated and different answers. I just need a simple way to convert my float into a byte array.
At present, I am using this:
float f = transform.position.y;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
bw.Write(f);
bw.Flush();
byte[] floatBytes = stream.ToArray();
bool reliable = true;
PlayGamesPlatform.Instance.RealTime.SendMessageToAll (reliable, floatBytes);
But i dont know how to read this later on. So far I have:
MemoryStream stream = new MemoryStream ();
BinaryReader reader = new BinaryReader (stream);
But I don’t know what do do from there.
Any help is greatly appreciated, thanks.