void receiveControlMessage(DodgerUpdateMessage dum) { Debug.Log("Getting DodgerUpdateMessage for player " + dum.playerNumber + ". i am " + this.playerNumber); player playerScript = getPlayer(dum.playerNumber); playerScript.protect = dum.dodging; playerScript.health = dum.health; }
DodgerUpdateMessage createDodgerControlMessage(bool dodging) { DodgerUpdateMessage message = new DodgerUpdateMessage(); message.dodging = dodging; message.playerNumber = playerNumber; message.health = getPlayer(playerNumber).health; return(message); }
// Update is called once per frame void Update() { GameObject networkingObject = GameObject.Find("Networking"); Client client = networkingObject.GetComponent <Client>(); if (client == null) { Debug.LogError("No client could be found. no networking"); } client.setClientListener(this); // input logic if (Input.GetKeyDown("space")) { spacePressed = true; } if (Input.GetKeyUp("space")) { spacePressed = false; } Debug.Log("space pressed " + spacePressed); DodgerUpdateMessage dum = createDodgerControlMessage(spacePressed); string serializedMsg = dum.encodeMessage(); if (serializedMsg != previousState) { Debug.Log("----------------------------------------------------"); this.messagesToSend.Add(dum); previousState = serializedMsg; // this is to make sure its still working locally. get rid of this once // networking is actually working //receiveControlMessage(serializedMsg); } }