From db8b95f710e938a7eecba8dbf74f773924196ccd Mon Sep 17 00:00:00 2001 From: Julia Butenhoff Date: Fri, 22 Apr 2022 18:22:07 -0500 Subject: [PATCH] Fixed Control Lock If Hit a Pitfall While Paused - Also fixed a minor bug where you could refresh the IP if you weren't the host --- Assets/Scripts/PlayerScripts/PlayerStats.cs | 12 ++++++ Assets/Scripts/UI/Lobby/LobbyUI.cs | 1 + Assets/Scripts/UI/PauseMenu.cs | 47 +++++++++++++++++++-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/PlayerScripts/PlayerStats.cs b/Assets/Scripts/PlayerScripts/PlayerStats.cs index db7ed54..b60a279 100644 --- a/Assets/Scripts/PlayerScripts/PlayerStats.cs +++ b/Assets/Scripts/PlayerScripts/PlayerStats.cs @@ -201,6 +201,18 @@ public class PlayerStats : MonoBehaviour else if (GameObject.FindGameObjectWithTag("FogSystem").GetComponent().isPlaying) { SetWeather(Weather.Fog); } + + StartCoroutine(UnPause()); + } + } + + IEnumerator UnPause() { + yield return new WaitForSecondsRealtime(3f); + + if (gameObject.transform.root.GetComponentInChildren().IsPaused) { + GameObject PauseMenu = GameObject.FindGameObjectWithTag("PauseMenu"); + PauseMenu.GetComponent().setPlayerControlsStateServerRPC(true); + PauseMenu.GetComponent().TurnOffPanelServerRPC(); } } diff --git a/Assets/Scripts/UI/Lobby/LobbyUI.cs b/Assets/Scripts/UI/Lobby/LobbyUI.cs index 5d5e896..eef02d9 100644 --- a/Assets/Scripts/UI/Lobby/LobbyUI.cs +++ b/Assets/Scripts/UI/Lobby/LobbyUI.cs @@ -353,6 +353,7 @@ public class LobbyUI : NetworkBehaviour { } public void RefreshIPAddress() { + if (!IsServer) { return; } StartCoroutine(GetIPAddress()); } diff --git a/Assets/Scripts/UI/PauseMenu.cs b/Assets/Scripts/UI/PauseMenu.cs index e89ca88..69f8917 100644 --- a/Assets/Scripts/UI/PauseMenu.cs +++ b/Assets/Scripts/UI/PauseMenu.cs @@ -53,6 +53,27 @@ public class PauseMenu : NetworkBehaviour { ControlsPanel.SetActive(false); ConfirmationPanel.SetActive(false); RespawnConfirmationPanel.SetActive(false); + + InvokeRepeating("checkForPaused", 0f, 2f); + } + + private void checkForPaused() { + GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); + + foreach (GameObject player in players) { + if (player.GetComponent().IsLocalPlayer) { + if (player.GetComponentInChildren() != null) + { + if (!player.GetComponentInChildren().IsPaused) + { + PauseMenuPanel.SetActive(false); + ControlsPanel.SetActive(false); + ConfirmationPanel.SetActive(false); + RespawnConfirmationPanel.SetActive(false); + } + } + } + } } void Update() { @@ -89,8 +110,6 @@ public class PauseMenu : NetworkBehaviour { // Turn off "Restart from Checkpoint" button for the king RestartButton.interactable = false; } - - } } @@ -98,7 +117,29 @@ public class PauseMenu : NetworkBehaviour { } [ServerRpc(RequireOwnership = false)] - private void setPlayerControlsStateServerRPC(bool newState, ServerRpcParams serverRpcParams = default) { + public void TurnOffPanelServerRPC(ServerRpcParams serverRpcParams = default) { + ClientRpcParams clientRpcParams = new ClientRpcParams + { + Send = new ClientRpcSendParams + { + TargetClientIds = new ulong[] { serverRpcParams.Receive.SenderClientId } + } + }; + + TurnOffPanelClientRPC(clientRpcParams); + } + + [ClientRpc] + private void TurnOffPanelClientRPC(ClientRpcParams clientRpcParams) + { + PauseMenuPanel.SetActive(false); + ControlsPanel.SetActive(false); + ConfirmationPanel.SetActive(false); + RespawnConfirmationPanel.SetActive(false); + } + + [ServerRpc(RequireOwnership = false)] + public void setPlayerControlsStateServerRPC(bool newState, ServerRpcParams serverRpcParams = default) { ClientRpcParams clientRpcParams = new ClientRpcParams { Send = new ClientRpcSendParams