34 lines
783 B
C#
34 lines
783 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
public class MuteToggler : MonoBehaviour {
|
|
public Sprite Unmuted, Muted;
|
|
|
|
[Header("If false, mutes FX")]
|
|
public bool MutesMusic = false;
|
|
|
|
// Start is called before the first frame update
|
|
void Start() {
|
|
GetComponent<Button>().onClick.AddListener(onButtonClick);
|
|
}
|
|
|
|
void onButtonClick() {
|
|
var state = MutesMusic ? AudioProvider.MuteBGM : AudioProvider.MuteSFX;
|
|
if (MutesMusic)
|
|
AudioProvider.MuteBGM = !state;
|
|
else {
|
|
AudioProvider.MuteSFX = !state;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update() {
|
|
var state = MutesMusic ? AudioProvider.MuteBGM : AudioProvider.MuteSFX;
|
|
|
|
var img = GetComponent<Image>().sprite = state ? Muted : Unmuted;
|
|
}
|
|
}
|