CapersProject/Assets/UltimateCleanGUIPack/Common/Scripts/Extra/SoundManager.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2024-06-03 18:26:03 +00:00
// Copyright (C) 2015-2021 gamevanilla - All rights reserved.
// This code can only be used under the standard Unity Asset Store End User License Agreement.
// A Copy of the Asset Store EULA is available at http://unity3d.com/company/legal/as_terms.
using UnityEngine;
using UnityEngine.UI;
namespace UltimateClean
{
/// <summary>
/// This class handles updating the sound UI widgets depending on the player's selection.
/// </summary>
public class SoundManager : MonoBehaviour
{
private Slider m_soundSlider;
private GameObject m_soundButton;
private void Start()
{
m_soundSlider = GetComponent<Slider>();
m_soundSlider.value = PlayerPrefs.GetInt("sound_on");
m_soundButton = GameObject.Find("SoundButton/Button");
}
public void SwitchSound()
{
AudioListener.volume = m_soundSlider.value;
PlayerPrefs.SetInt("sound_on", (int)m_soundSlider.value);
if (m_soundButton != null)
{
m_soundButton.GetComponent<SoundButton>().ToggleSprite();
}
}
}
}