私は友達のために小さなゲームに取り組んでいます。これまでのところ、私はネットワークを正しく取得しており、両方のプレーヤーが飛び回ることができ、すべてが同期しています.
これで、次のようにスポーンする発射体 (レーザー) を追加しました。
if (_mou.LeftButton == ButtonState.Pressed
&& oldState.LeftButton
!= ButtonState.Released)
{
if (timeSinceShot > timePerShot)
{
timeSinceShot = 0;
bulletRotation = rotation; //Rotation of the players ship
laser.addLaser(myID, bulletRotation, localPosition);
}
}
これは正常に動作し、私の船からレーザーを発射しますが、まだ表示されません。
今私が発砲するとき、私はこれを呼び出します:
om.Write(bulletRotation); //Sends the rotation to the server
サーバーがそれを受信すると、それを撃った人を含むすべてのプレイヤーに送り返します。
クライアントでデータを受け取り、それをレーザー リストに書き込む方法は次のとおりです。
if (who != myID)
{
try
{
float laserR = msg.ReadFloat();
laser.addLaser(who, laserR, player.players[i].position);
}
catch { }
}
これを 2 つのクライアントでテストして起動すると、2 番目のクライアントで起動していることがわかります。ただし、2 番目のクライアントだけでなく、クライアントの 2 番目のプレーヤーでも発生します。
編集: 誰が RemoteUniqueIdentifier であり、myID はクライアントの RemoteUniqueIdentifier です
これが私の問題の写真です。 http://i.stack.imgur.com/CYJyW.png (担当者が 10 人いないのでまだアップロードできません)
編集2:
これは、サーバーがすべてのプレイヤーにデータを送信する方法です。
foreach (NetConnection player in server.Connections)
{
// ... send information about every other player (actually including self)
foreach (NetConnection otherPlayer in server.Connections)
{
// send position update about 'otherPlayer' to 'player'
NetOutgoingMessage om = server.CreateMessage();
// write who this position is for
om.Write(player.RemoteUniqueIdentifier);
om.Write(otherPlayer.RemoteUniqueIdentifier);
if (otherPlayer.Tag == null)
otherPlayer.Tag = new float[4];
float[] pos = otherPlayer.Tag as float[];
om.Write(pos[0]); // velocity X
om.Write(pos[1]); // velocity X
om.Write(pos[2]); // rotation
if (!noLasers)
{
om.Write(pos[3]); // bullet rotation
}
// send message
server.SendMessage(om, player, NetDeliveryMethod.Unreliable);
}
}