Skip to content

Instantly share code, notes, and snippets.

@glebov21
Created February 21, 2018 15:55
Show Gist options
  • Save glebov21/5d4c5fce9dc4e133ddd0ba81e783ee14 to your computer and use it in GitHub Desktop.
Save glebov21/5d4c5fce9dc4e133ddd0ba81e783ee14 to your computer and use it in GitHub Desktop.
Mute (unity3d)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class MuteButton : MonoBehaviour {
float defaultVolume = 1f;
void Awake()
{
AudioListener.volume = IUMobileSettings.CommonVolume;
GetComponent<Button>().onClick.SetListener(() =>
{
if (AudioListener.volume > 0)
{
defaultVolume = AudioListener.volume;
AudioListener.volume = 0f;
}
else
{
if(defaultVolume == 0)
{
defaultVolume = 1;
}
AudioListener.volume = defaultVolume;
}
IUMobileSettings.CommonVolume = AudioListener.volume;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment