private void SVolume() { AudioSource[] dlaczego = FindObjectsOfType <AudioSource>(); foreach (AudioSource AS in dlaczego) { AS.volume = volume * AS.GetComponent <SoundVolCTRL>().startVol; } }
private void Awake() { if (FindObjectsOfType <inGameSettings>().Length > 1) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); SFXsources = GameObject.FindGameObjectsWithTag("SFX")?.Select(AS => AS.GetComponent <AudioSource>()).ToArray(); MUSICsources = GameObject.FindGameObjectsWithTag("MUSIC")?.Select(AS => AS.GetComponent <AudioSource>()).ToArray(); if (PlayerPrefs.HasKey("SFXValue")) { SFXValue = PlayerPrefs.GetFloat("SFXValue"); } if (PlayerPrefs.HasKey("MUSICValue")) { MUSICValue = PlayerPrefs.GetFloat("MUSICValue"); } SceneManager.activeSceneChanged += (Old, New) => { #if UNITY_ANDROID GameObject.FindGameObjectWithTag("Touchscreen")?.SetActive(true); #endif #if UNITY_STANDALONE GameObject.FindGameObjectWithTag("Touchscreen")?.SetActive(false); #endif SFXsources = GameObject.FindGameObjectsWithTag("SFX")?.Select(AS => AS.GetComponent <AudioSource>()).ToArray(); MUSICsources = GameObject.FindGameObjectsWithTag("MUSIC")?.Select(AS => AS.GetComponent <AudioSource>()).ToArray(); foreach (AudioSource SFXsource in SFXsources) { SFXsource.volume = SFXValue; } foreach (AudioSource MUSICsource in MUSICsources) { MUSICsource.volume = MUSICValue; } if (New.name != "Menu" && Old.name != "Menu") { transform.GetChild(0).gameObject.SetActive(true); } else if ((New.name == "Menu" || Old.name == "Menu") && transform.GetChild(0).gameObject.activeInHierarchy) { var c = FindObjectOfType <counter>(); c.tim = 0; c.UpdateC(); } }; }