1- Go to Assets → Create → Audio Mixer
2- Rename it as MasterMixer and double click on it
3- In the Groups section click on + and add a group. Rename it as Music
4- Select your group(Music), right click on the free space of the Attenuation in the inspector, click Expose.
5- Click on Exposed Parameters in the Audio Mixer panel. Rename parameter name as musicVol and press enter
6- Create the Game Object and name it as AudioObj. Click Add Component in the inspector and add Audio Source
7- Click on small circle in the right side of the AudioClip. Select your audio
8- Click small circle in the right side of the Output. Select MasterMixer → Master → Music
9- Go to Assets → Create → C# script
10- Add this code. (Use SetFloat name as the parameter name you gave to the Exposed Parameters)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
public class AudioScript : MonoBehaviour {
public AudioMixer masterMixer;
public void SetSound(float soundLevel)
{
masterMixer.SetFloat (“musicVol”, soundLevel);
}
}
11- Create a Game Object name it as AudioScriptObj and drag the script to it
12- Drag Audio Mixer from the project panel and drop to the masterMixer
13- Go to Game Object → UI → Slider
14- Click the slider. In the inspector click the + of the On Value Changed
15- Drag the AudioScriptObj to the object and click on function list. select AudioScript → SetSound (it’s under Dynamic float)
16- Click the slider and change the Min Value to -80 and Max Value to 0
That’s it. Cheers!