- Home /
Toggle Button for Sound On/Off
I am using NGUI for menu creation. For sound on/off purpose, I am using toggle button which works correctly.
So what next I have to do ? Also this time I searched other posts for my current solution. If you more information then I am ready to provide.
Answer by Exalia · Jan 21, 2014 at 07:43 AM
You can make your code independent of previous button state
Example :
Button Script :
public GameObject audioSource;
bool soundToggle = true;
OnGUI()
{
soundToggle = !soundToggle;
if(soundToggle)
{
audioSource.SetActive(true);
//audioSource.mute = true;
//audioSource.volume = 1.0f;
}
else
{
audioSource.SetActive(false);
//audioSource.mute = false;
//audioSource.volume = 0.0f;
}
}
When the button is pushed toggle a boolean, set the AudioListener in your scene to inactive when the boolean is false.
Thanks for you reply but at present I don't know how to get current state of the button? and How to use that state for enable / disable audio listener?
Basically you misunderstand my question. I already know core unity thing to perform this but I am first time using NGUI toggle button to implement same thing. So you have to help me in this.
Your answer
Follow this Question
Related Questions
Setting Background using NGUI 0 Answers
Placing button at corner using NGUI 2 Answers
UI Button should stay highlighted on click 2 Answers
How Do I Turn Off Toggle in a ToggleGroup ? 1 Answer
In sequence position game objects 1 Answer