In the Hierarchy i have one Main Camera with Audio Listener. In the Hierarchy I have AudioPanel and two child Sliders.
And the AudioManager script that attached to the AudioPanel:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
[System.Serializable]
public class AudioManager : MonoBehaviour
{
public Slider musicVolume;
public Slider effectsVolume;
private void SetMusicListenerVolume()
{
AudioListener.volume = musicVolume.value;
}
public void ApplyMusicSettings()
{
SetMusicListenerVolume();
}
private void SetEffectsListenerVolume()
{
AudioListener.volume = effectsVolume.value;
}
public void ApplyEffectsSettings()
{
SetEffectsListenerVolume();
}
}
Now in the Hierarchy I have some Audio Sources components for the sound effects and I want to control them with the Slider (1).
And to control the music sound with the Slider. The music sound have his own Audio Source.
The problem is that the AudioListener in the script control all the Audio Sources. Music and Effects. Or maybe only the Music ? U'm not sure. But when i change both sliders when the game is running it's changing the music volume.
My question/s is how to control with Slider only the volume of the music and with Slider (1) the effects volume ?
And how can i get all the effects audio sources in the script and control the volume of them using the Slider (1) ?
The audio source component of the music is attached to GameObject name Sound. All the other audio sources components are effects and are in some places in the Hierarchy.