Here you can see what the code does:
Screen capture - ce457f1e8e29f9ff5776e0a9288b6c90 - Gyazo
I’m not sure what you’re doing but I’m assuming that you’re having a speaker icon that gets switched to a muted one when there is no volume playing? I’ve written a script like such before and I will happily give you the code for it.
First you will need to have everything done before you actually can switch the 2 textures with one another, with this I mean is that you pre-add the 2 textures to the script in the inspector before even executing the code (if you haven’t)
Add these 2 variables
public Texture mutedIcon;
public Texture unmutedIcon;
And for my own code I had a slider which you could slide which would also change the icon according to how loud the sound/volume was if you’re after that add this variable
public float hSliderValue = 0.0F;
Additional variables:
Boolean to determine wether the music was muted or not
public bool mutedMusic = false;
I haven’t done anything with resolution so you might have to change some of the code down here.
The OnGUI:
void OnGUI(){
if(GUI.Button (new Rect(40, 0, 40, 40), icon)){
mutedMusic = mutedMusic ? music.mute = false : music.mute = true;
hSliderValue = mutedMusic ? 0 : 10;
}
//wether the slider was on 0 or if the music is muted
if(mutedMusic || hSliderValue == 0){
icon = mutedIcon;
mutedMusic = true;
}
//if volume is higher than 0.1 basically
if(hSliderValue >= 0.1f){
icon = unmutedIcon;
music.mute = false;
mutedMusic = false;
}
//the slider that lets you control the volume
hSliderValue = GUI.HorizontalSlider(new Rect(0, 40, 100, 30), hSliderValue, 0.0f, 10.0f);
AudioListener.volume = hSliderValue/10.0f;
}
I’ve written the code quite some time ago so there might be some errors in it, if you need any more help you can ask, if not you can put this as an answer to your question and potentionally add a comment to it to make things clear that I haven’t made clear in my code x).
Cheers!