Fix being able to edit the ui when not paused

This commit is contained in:
2025-06-25 13:36:12 -07:00
parent 866661f32a
commit 62c339f09a
2 changed files with 20 additions and 10 deletions

View File

@@ -715,6 +715,7 @@ public class GamePlayer : MonoBehaviour
Cursor.lockState = CursorLockMode.Locked;
backgroundMusic.Play();
pausePanel.SetActive(false);
if (GamePlayerPauseMenu.Instance.editingUI == true) GamePlayerPauseMenu.Instance.ToggleEditingUI();
}
void OnApplicationPause(bool pause)

View File

@@ -4,6 +4,7 @@ using UnityEngine.UI;
public class GamePlayerPauseMenu : MonoBehaviour
{
public static GamePlayerPauseMenu Instance;
public Button backButton;
public Button continueButton;
public Button editUiButton;
@@ -15,9 +16,11 @@ public class GamePlayerPauseMenu : MonoBehaviour
public TMP_Text scoreText;
public TMP_Text highScoreText;
public TMP_Text boostText;
public bool editingUI = false;
void Awake()
{
Instance = this;
musicSlider.value = PlayerPrefs.GetFloat("musicVolume", 1f);
sfxSlider.value = PlayerPrefs.GetFloat("sfxVolume", 1f);
backButton.onClick.AddListener(async () =>
@@ -38,16 +41,7 @@ public class GamePlayerPauseMenu : MonoBehaviour
});
editUiButton.onClick.AddListener(() =>
{
musicSlider.gameObject.SetActive(!musicSlider.gameObject.activeSelf);
sfxSlider.gameObject.SetActive(!sfxSlider.gameObject.activeSelf);
backButton.gameObject.SetActive(!backButton.gameObject.activeSelf);
continueButton.gameObject.SetActive(!continueButton.gameObject.activeSelf);
editUiButton.transform.GetChild(0).GetComponent<TMP_Text>().text = editUiButton.transform.GetChild(0).GetComponent<TMP_Text>().text == "Edit UI" ? "Done" : "Edit UI";
resetUiButton.gameObject.SetActive(!resetUiButton.gameObject.activeSelf);
fpsText.GetComponent<DraggableUI>().canDrag = !fpsText.GetComponent<DraggableUI>().canDrag;
scoreText.GetComponent<DraggableUI>().canDrag = !scoreText.GetComponent<DraggableUI>().canDrag;
highScoreText.GetComponent<DraggableUI>().canDrag = !highScoreText.GetComponent<DraggableUI>().canDrag;
boostText.GetComponent<DraggableUI>().canDrag = !boostText.GetComponent<DraggableUI>().canDrag;
ToggleEditingUI();
});
resetUiButton.onClick.AddListener(() =>
{
@@ -61,4 +55,19 @@ public class GamePlayerPauseMenu : MonoBehaviour
PlayerPrefs.DeleteKey("DraggedUIBoostText");
});
}
public void ToggleEditingUI()
{
editingUI = !editingUI;
musicSlider.gameObject.SetActive(!musicSlider.gameObject.activeSelf);
sfxSlider.gameObject.SetActive(!sfxSlider.gameObject.activeSelf);
backButton.gameObject.SetActive(!backButton.gameObject.activeSelf);
continueButton.gameObject.SetActive(!continueButton.gameObject.activeSelf);
editUiButton.transform.GetChild(0).GetComponent<TMP_Text>().text = editUiButton.transform.GetChild(0).GetComponent<TMP_Text>().text == "Edit UI" ? "Done" : "Edit UI";
resetUiButton.gameObject.SetActive(!resetUiButton.gameObject.activeSelf);
fpsText.GetComponent<DraggableUI>().canDrag = !fpsText.GetComponent<DraggableUI>().canDrag;
scoreText.GetComponent<DraggableUI>().canDrag = !scoreText.GetComponent<DraggableUI>().canDrag;
highScoreText.GetComponent<DraggableUI>().canDrag = !highScoreText.GetComponent<DraggableUI>().canDrag;
boostText.GetComponent<DraggableUI>().canDrag = !boostText.GetComponent<DraggableUI>().canDrag;
}
}