Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using TMPro;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class SettingsMenu : MonoBehaviour
- {
- public GameObject canvasSettings;
- public GameObject settingsButton;
- public GameObject voiceButton;
- public TextMeshProUGUI muteText;
- private bool buttonIsClicked;
- private int music;
- void Start()
- {
- //jeżeli masz już voice, weź go i zobacz czy włączyć muzykę
- //jeżeli nie ma, włącz muzykę i ustaw voice jako 1
- if (PlayerPrefs.HasKey("voice"))
- {
- music = PlayerPrefs.GetInt("voice");
- if (music == 1) { AudioListener.volume = 1;
- muteText.GetComponent<TextMeshProUGUI>().text = "Mute Voice";
- }
- if(music == 0) { AudioListener.volume = 0;
- muteText.GetComponent<TextMeshProUGUI>().text = "Un-Mute Voice";
- }
- }
- else
- {
- PlayerPrefs.SetInt("voice", 1);
- AudioListener.volume = 1;
- muteText.GetComponent<TextMeshProUGUI>().text = "Mute Voice";
- }
- canvasSettings.SetActive(false);
- buttonIsClicked = false;
- settingsButton.GetComponent<Button>().onClick.AddListener(Toggle);
- voiceButton.GetComponent<Button>().onClick.AddListener(Voice);
- }
- void Update()
- {
- if (buttonIsClicked) { canvasSettings.SetActive(true); } else { canvasSettings.SetActive(false); }
- }
- public void Toggle()
- {
- if(!buttonIsClicked) { buttonIsClicked = true; } else { buttonIsClicked = false; }
- Time.timeScale = 0f;
- Debug.Log(buttonIsClicked);
- }
- public void Voice()
- {
- music = PlayerPrefs.GetInt("voice");
- //jeżeli voice to 1, ustaw voice na 0 i wylacz muzyke
- if(music == 1) {
- PlayerPrefs.SetInt("voice", 0);
- AudioListener.volume = 0;
- muteText.GetComponent<TextMeshProUGUI>().text = "Un-Mute Voice";
- }
- //jezeli voice to 0, ustaw voice na 1 i wlacz muzyke
- if (music == 0)
- {
- PlayerPrefs.SetInt("voice", 1);
- AudioListener.volume = 1;
- muteText.GetComponent<TextMeshProUGUI>().text = "Mute Voice";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement