I have a script that plays an ad every time you press the ‘play again’ or ‘home’ buttons.
public void ShowAds()
{
if (Advertisement.IsReady("video"))
{
Advertisement.Show("video");
if (Advertisement.isShowing)
{
Time.timeScale = 0f;
}
}
}
This works perfectly fine, however I need to set my volume to 0 when the ad is playing and set it back to whatever it was if it isn’t. I currently set my volume using a UI slider.
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class OptionsMenu : MonoBehaviour {
public AudioMixer mixer;
public Slider slider;
public void SetVolume(float volume)
{
mixer.SetFloat("Volume", volume);
}
public void Start()
{
SetVolume(PlayerPrefs.GetFloat("Volume", 0));
slider.value = PlayerPrefs.GetFloat("Volume");
Time.timeScale = 1f;
}
public void OnDisable()
{
float Volume = 0f;
mixer.GetFloat("Volume", out Volume);
PlayerPrefs.SetFloat("Volume", Volume);
PlayerPrefs.Save();
}
}
Please help!