Game Development Reference
In-Depth Information
}
}
public void SetSFX(float sfxVolume)
{
AudioSource[] audios =
GameObject.FindObjectsOfType<AudioSource>();
foreach(AudioSource source in audios)
{
source.volume = sfxVolume;
}
}
public void SetAtm(float atmVolume)
{
AudioSource[] audios =
GameObject.FindObjectsOfType<AudioSource>();
foreach(AudioSource source in audios)
{
source.volume = atmVolume;
}
}
In each of the preceding functions, we pass a float variable, which will be the
new volume. Next, we create an array of audio sources, which we will grab from the
scene. Finally, for each of the audio sources, we assign its volume to the new volume
value of our passed variable.
Setting the speaker mode
Next, we'll set the speaker mode for the audio output. This will affect how the player
will hear your audio. A player who uses headphones might want to use surround
sound. A player who uses speakers to hear your game may want to use the stereo
sound instead. Add this function to the script:
Search WWH ::




Custom Search