Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mute Button Problem

Discussion in 'Audio & Video' started by truckcarr, Feb 14, 2016.

  1. truckcarr

    truckcarr

    Joined:
    Feb 14, 2016
    Posts:
    3
    Hey guys, I'm new to unity and I'm trying to make a simple mute button. I have gotten everything to work so far except for one thing. So basically i have two objects, one that plays music and one that is the ui toggle button. I use a PlayerPref variable to make sure the music is muted or not and it works fine and dandy but when i go back to the scene with the button the isOn always starts as true even though i have this script attached to the toggle button.

    void Start()
    {
    if (PlayerPrefs.GetInt("toggeled") == 1)
    {
    gameObject.GetComponent<Toggle>().isOn = false;
    }
    if (PlayerPrefs.GetInt("toggeled") == 0)
    {
    gameObject.GetComponent<Toggle>().isOn = true;
    }

    }

    For some reason if i mute the audio, play a round, and come back to the scene it shows as if its unmuted.
     
  2. geek_freek

    geek_freek

    Joined:
    Aug 26, 2014
    Posts:
    51
    It could probably be the case of PlayerPrefs not being saved or set . Where are you setting your PlayerPrefs and have you crosschecked PlayerPrefs if its setting or not ?

    On Windows, PlayerPrefs are stored in the registry under HKCU\Software\[company name]\[product name] key, where company and product names are the names set up in Project Settings.