- Home /
One Slider Control More Than One Sound
I want to ask. how to make 1 slider control more than 1 sound? when i make AudioSource to array AudioSource[] to put 3 sound, the error said that "SFXVolume.Volume" does not contain a definition of volume.
public Slider SFXSlider;
public AudioSource SFXVolume;
public float SFX;
// Use this for initialization
void Start () {
SFXSlider.value=PlayerPrefs.GetFloat ("SFXMusic");
LoadSFX ();
SFXVolume.volume = SFX;
}
// Update is called once per frame
void Update () {
SFXVolume.volume = SFXSlider.value;
}
public void saveMusic(){
PlayerPrefs.SetFloat ("SFXMusic",SFXSlider.value);
}
void LoadSFX(){
if (PlayerPrefs.HasKey("SFXMusic")) {
SFX = PlayerPrefs.GetFloat("SFXMusic");
} else {
SFX = 1;
}
}
Sorry for my bad english and thanks before :)
Answer by Nomenokes · Jul 23, 2018 at 04:50 AM
If I understand correctly, your code with the array had
public AudioSource[] SFXVolume;
instead of
public AudioSource SFXVolume;
In this case, SFXVolume
is no longer an AudioSource but an array of AudioSources. When you tried to access volume
, it said that an array does not have a definition for volume, which is correct. Arrays don't have volumes. What you need to do is access each AudioSource within the array by iterating through the array and modifying each one.
foreach(AudioSource eachSource in SFXVolume){ //where SFXVolume is an AudioSource[]
eachSource.volume = SFXSlider.value;
}
I may have not correctly understood what you said, please correct me if I am wrong.
Your English is fine by the way :)
Cheers,
Nomenokes
Your answer
Follow this Question
Related Questions
Separate Listeners for Sound FX and Music? 0 Answers
Problems with a racing game level. 0 Answers
Audio controls disabled??! 0 Answers
How to create impact sounds? 3 Answers
Optimised audio system design for mobile 0 Answers