using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class SettingsMenu : MonoBehaviour
{
public AudioMixer audioMixer;
public Dropdown resolutionDropDown;
[SerializeField]
private Slider _volumeSlider;
[SerializeField]
private Dropdown _dropDownQuality;
private Resolution[] resolutions;
private void Start()
{
resolutions = Screen.resolutions;
resolutionDropDown.ClearOptions();
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + " x " + resolutions[i].height;
options.Add(option);
if (resolutions[i].width == Screen.currentResolution.width &&
resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex = i;
}
}
resolutionDropDown.AddOptions(options);
resolutionDropDown.value = currentResolutionIndex;
resolutionDropDown.RefreshShownValue();
}
public void SetVolume()
{
float volume = _volumeSlider.value;
Debug.Log("Volume " + volume);
audioMixer.SetFloat("Volume", volume);
}
public void SetQuality()
{
int qualityIndex = _dropDownQuality.value;
QualitySettings.SetQualityLevel(qualityIndex);
}
public void SetFullScreen()
{
Screen.fullScreen = !Screen.fullScreen;
}
}
The warning is on line 48 :
audioMixer.SetFloat("Volume", volume);
Screenshot of the Audio Mixer inspector settings I did expose to the Volume :
After exposing there is the arrow pointing to the right above the Volume :
But still getting the warning when running the game and changing the Volume slider.
It should change the volume in the audio mixer but instead itâs showing this warning.
I havenât used mixers and their named properties, but I am suspicious about the warning graphic, specifically what is contained within the quotes in the highlighted question. Your screencap says:
Expose âVolume (of Master)â to script
This makes me think that the name is âVolume (of Master)â but maybe Iâm wrong, as I havenât used this specific mechanism. It should be easy to try and test it.
If you want to see a list of the exposed parameters to find out what they are called, copy and paste them, or rename them, or delete them, then you can click on the âExposed Parametersâ button on the audio mixer. Itâs kinda hiding in plain view. It is visible in your screenshots. Itâs just below âAudio Mixerâ at the top. âExposed Parameters (1)â
As far as naming params go, try to be pretty specific. âVolumeâ isnât specific. MasterVolume is specific. You donât want to have to rename things in the future when your mixer grows because you were ambiguous in the beginning. Every time you change a param name you have to also change it in the code that hooks up to that param, so create a decent naming convention from the start.You want to read the name, and be able to know exactly what control it is pointing to on the mixer, without looking at the mixer.
I agree with 100% of what @Hikiko66 said above, and I want to add this: make a series of const strings in one central class to keep from going insane:
public static class MyMixer
{
public const string s_MasterVolume = "Master Volume";
// etc.
}
That way you only use the variable s_MasterVolume anywhere you need that, and if you do rename stuff, you have one central place to go and be confident you got all places it is used.
For those who get this error message just do the following:
1- Find your audio source and double click to open
2- Look for âExposed Parametersâ in the upper right corner of the Audio Mixer tab
3- Expand the âExposed Parametersâ select the parameter you are trying to access by the script and change the name to the same name you used in the script (or change the name in the script to the name that appears in the Exposed Parameters)