Add draggable UI to game player

This commit is contained in:
2025-06-25 00:58:26 -07:00
parent 73822ebb94
commit 2aed4e416a
4 changed files with 718 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -5,9 +6,15 @@ public class GamePlayerPauseMenu : MonoBehaviour
{
public Button backButton;
public Button continueButton;
public Button editUiButton;
public Button resetUiButton;
public AudioSource songLoop;
public Slider musicSlider;
public Slider sfxSlider;
public TMP_Text fpsText;
public TMP_Text scoreText;
public TMP_Text highScoreText;
public TMP_Text boostText;
void Awake()
{
@@ -29,5 +36,29 @@ public class GamePlayerPauseMenu : MonoBehaviour
PlayerPrefs.SetFloat("sfxVolume", value);
PlayerPrefs.Save();
});
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;
});
resetUiButton.onClick.AddListener(() =>
{
fpsText.transform.localPosition = new Vector2(-432.5f, 375f);
scoreText.transform.localPosition = new Vector2(0f, 290f);
highScoreText.transform.localPosition = new Vector2(0f, 220f);
boostText.transform.localPosition = new Vector2(0f, 170f);
PlayerPrefs.DeleteKey("DraggedUIFPSText");
PlayerPrefs.DeleteKey("DraggedUIScoreText");
PlayerPrefs.DeleteKey("DraggedUIHighScoreText");
PlayerPrefs.DeleteKey("DraggedUIBoostText");
});
}
}