// Server - when the client chooses to drop the flag (when they shoot a bullet) public void OnFlagDrop(NetworkMessage _networkMessage) { FlagDropMessage netMsg = _networkMessage.ReadMessage <FlagDropMessage>(); Debug.Log("On Flag Drop"); // update our flag this.gameFlag.StartCoroutine(this.gameFlag.DropFlag()); // Update our list for (int i = 0; i < this.numPlayers; i++) { if (this.playerInfoList[i].playerObjectId == netMsg.playerId) { PlayerInfo pInfo = this.playerInfoList[i]; pInfo.hasFlag = false; this.playerInfoList[i] = pInfo; } } // update client flags FlagInteractionMessage msg = new FlagInteractionMessage(); msg.playerId = netMsg.playerId; msg.flagId = this.flagId; msg.isHeld = false; NetworkServer.SendToAll(CustomMsgType.Flag, msg); }
// Client - When a client collides with the flag, or a bullet causing them to drop it public void OnFlagInteraction(NetworkMessage _networkMessage) { Debug.Log("On Flag Interaction Client"); FlagInteractionMessage msg = _networkMessage.ReadMessage <FlagInteractionMessage>(); Flag clientFlag = NetworkHelper.GetObjectByNetIdValue <Flag>((uint)msg.flagId, false); clientFlag.OnFlagInteraction(msg.isHeld); PlayerManager tempPlayer = NetworkHelper.GetObjectByNetIdValue <PlayerManager>((uint)msg.playerId, false); tempPlayer.SetHasFlag(msg.isHeld); }
// Server - When a client collides with the flag, or a bullet causing them to drop it public void OnFlagInteraction(bool _isHeld, int _playerId) { Debug.Log("On Flag Interaction"); // Update our list for (int i = 0; i < this.numPlayers; i++) { if (this.playerInfoList[i].playerObjectId == _playerId) { PlayerInfo pInfo = this.playerInfoList[i]; pInfo.hasFlag = _isHeld; this.playerInfoList[i] = pInfo; } } // Send msg to clients FlagInteractionMessage msg = new FlagInteractionMessage(); msg.playerId = _playerId; msg.flagId = this.flagId; msg.isHeld = _isHeld; NetworkServer.SendToAll(CustomMsgType.Flag, msg); }