// Use this for initialization void Start() { var approval = new ConnectionApprovalMessage { Name = "James" }; var config = new NetPeerConfiguration("Tanks2"); _client = new NetClient(config); _messageHandler = new GameMessageHandler(_client); _client.Start(); _client.Connect("localhost", 4200, _messageHandler.Encode(approval)); }
// Update is called once per frame void Update() { NetIncomingMessage msg; while ((msg = _client.ReadMessage()) != null) { ProcessMessage(msg); _client.Recycle(msg); } var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); var controls = new PlayerInput(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), mousePos.x, mousePos.y); var approval = new ConnectionApprovalMessage { Name = "Test" }; _client.SendMessage(_messageHandler.Encode(new PlayerControlUpdateMessage { Controls = controls }), NetDeliveryMethod.UnreliableSequenced, (int)GameMessageType.PlayerControls); }