這是一款多層遊戲,我需要發送服務器的位置和旋轉值,然後再從那裏取回.Google只允許通過字節發送。這就是我想要的。如何發送transform.position和transform.rotation值?
float aa;
float bb;
float cc;
byte[] xx =new byte[5];
byte[] yy =new byte[5];
byte[] zz =new byte[5];
Update()
{
aa=transform.postion.x;
bb=transform.postion.y;
cc = transform.postion.z;
xx = System.BitConverter.GetBytes (aa);
yy = System.BitConverter.GetBytes(bb);
zz = System.BitConverter.GetBytes(cc);
PlayGamesPlatform.Instance.RealTime..SendMessageToAll(false,xx);
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false,yy);
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false,zz);
}
如果我這樣發送,我怎麼知道發送的數據是什麼?
public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data) {
if(data[0]==(byte)'R')
{
//Convert back the data
float xyz = System.BitConverter.ToSingle(data,0);
}
}
所以我的問題是如何通過Unity3D發送位置值和輪換在Google Play多人遊戲?你們好嗎?這種方法沒有給出任何編譯錯誤,但我有強烈的感覺,這是不正確的方式,有比這更好的方法。
你有沒有得到任何解決方案? –