private void ParseMessage(byte[] data) { switch ((ClientMessages)data[0]) { case ClientMessages.PlayerFound: var isAuthority = data[1] == 0xFF; Sender.Send(new StartRoomSessionMessage(isAuthority)); break; case ClientMessages.WorldState: using (var stream = new MemoryStream(data)) using (var reader = new BinaryReader(stream)) { reader.ReadByte(); var stateMessage = new WorldStateMessage { PartnerPosition = reader.ReadSingle(), PartnetVelocity = reader.ReadSingle(), BallPosition = new Vector2(reader.ReadSingle(), reader.ReadSingle()), BallVelocity = new Vector2(reader.ReadSingle(), reader.ReadSingle()) }; Sender.Send(stateMessage); } break; case ClientMessages.Platform: using (var stream = new MemoryStream(data)) using (var reader = new BinaryReader(stream)) { reader.ReadByte(); var stateMessage = new PartnetPlatformMessage { PartnerPosition = reader.ReadSingle(), PartnerVelocity = reader.ReadSingle() }; Sender.Send(stateMessage); } break; default: Debug.LogError($"Not known event {data[0]:X}"); break; } }
private void HandlePartnerState(PartnetPlatformMessage obj) { Enemy.transform.localPosition = new Vector3(-obj.PartnerPosition, Enemy.transform.localPosition.y, Enemy.transform.localPosition.z); Enemy.GetComponent <Rigidbody2D>().velocity = new Vector2(-obj.PartnerVelocity, 0); }