void OnData(DataStreamReader stream) { NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp); stream.ReadBytes(bytes); string recMsg = Encoding.ASCII.GetString(bytes.ToArray()); MessageHeader header = JsonUtility.FromJson <MessageHeader>(recMsg); switch (header.type) { case MessageType.HEARTBEAT: Debug.Log("Heartbeat"); break; case MessageType.BATTLE_MSG: var bMsg = JsonUtility.FromJson <BattleMessage>(recMsg); BattleData.SetBattleData(bMsg); Debug.Log("Battle Started"); GameController.Instance.StartMultiplayerBattle(); break; case MessageType.MOVE_MSG: //Move Received var mMsg = JsonUtility.FromJson <MoveMessage>(recMsg); move = mMsg; Debug.Log("Move " + mMsg.MoveName + " Received"); break; default: Debug.Log("Unrecognized message received!"); break; } }