【问题标题】:How to send transform.position and transform.rotation values?如何发送 transform.position 和 transform.rotation 值?
【发布时间】:2014-05-08 11:13:37
【问题描述】:

这是一个多层游戏,我需要发送服务器的位置和旋转值并再次从那里取回。谷歌只允许通过字节发送。这就是我正在尝试的。

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 Multiplayer 中发送位置值和旋转?你们怎么样?这种方法不会产生任何编译错误,但我有一种强烈的感觉,这不是正确的方法,还有比这更好的方法。

【问题讨论】:

  • 你有解决办法吗?

标签: android unity3d google-play-services multiplayer


【解决方案1】:

在您的示例中使用State Synchronization 会容易得多。但是,请注意,多人游戏始终是一种权衡游戏,您必须非常确定自己想要实现的目标。大规模 RTS 的网络代码与快节奏的 FPS 完全不同。

【讨论】:

  • 我正在使用 Google Play 多人游戏服务。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-29
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
  • 2021-07-02
相关资源
最近更新 更多