SHARE
TWEET

Untitled

a guest Mar 26th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.UI;
  4. using TMPro;
  5. using UnityEngine;
  6. using UnityEngine.SceneManagement;
  7.  
  8. public class SettingsMenu : MonoBehaviour
  9. {
  10.     public GameObject canvasSettings;
  11.     public GameObject settingsButton;
  12.     public GameObject voiceButton;
  13.     public TextMeshProUGUI muteText;
  14.     private bool buttonIsClicked;
  15.     private int music;
  16.  
  17.     void Start()
  18.     {
  19.  
  20.         //jeżeli masz już voice, weź go i zobacz czy włączyć muzykę
  21.         //jeżeli nie ma, włącz muzykę i ustaw voice jako 1
  22.         if (PlayerPrefs.HasKey("voice"))
  23.         {
  24.             music = PlayerPrefs.GetInt("voice");
  25.             if (music == 1) { AudioListener.volume = 1;
  26.                 muteText.GetComponent<TextMeshProUGUI>().text = "Mute Voice";
  27.             }
  28.             if(music == 0) { AudioListener.volume = 0;
  29.                 muteText.GetComponent<TextMeshProUGUI>().text = "Un-Mute Voice";
  30.             }
  31.         }
  32.         else
  33.         {
  34.             PlayerPrefs.SetInt("voice", 1);
  35.             AudioListener.volume = 1;
  36.             muteText.GetComponent<TextMeshProUGUI>().text = "Mute Voice";
  37.         }
  38.         canvasSettings.SetActive(false);
  39.         buttonIsClicked = false;
  40.         settingsButton.GetComponent<Button>().onClick.AddListener(Toggle);
  41.         voiceButton.GetComponent<Button>().onClick.AddListener(Voice);
  42.     }
  43.  
  44.     void Update()
  45.     {
  46.         if (buttonIsClicked) { canvasSettings.SetActive(true); } else { canvasSettings.SetActive(false);  }
  47.     }
  48.     public void Toggle()
  49.     {
  50.         if(!buttonIsClicked) { buttonIsClicked = true; } else { buttonIsClicked = false; }
  51.         Time.timeScale = 0f;
  52.         Debug.Log(buttonIsClicked);
  53.     }
  54.     public void Voice()
  55.     {
  56.         music = PlayerPrefs.GetInt("voice");
  57.         //jeżeli voice to 1, ustaw voice na 0 i wylacz muzyke
  58.         if(music == 1) {
  59.             PlayerPrefs.SetInt("voice", 0);
  60.             AudioListener.volume = 0;
  61.             muteText.GetComponent<TextMeshProUGUI>().text = "Un-Mute Voice";
  62.         }
  63.         //jezeli voice to 0, ustaw voice na 1 i wlacz muzyke
  64.         if (music == 0)
  65.         {
  66.             PlayerPrefs.SetInt("voice", 1);
  67.             AudioListener.volume = 1;
  68.             muteText.GetComponent<TextMeshProUGUI>().text = "Mute Voice";
  69.         }
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top