Book Image

Unity Game Development Scripting

By : Kyle D'Aoust
Book Image

Unity Game Development Scripting

By: Kyle D'Aoust

Overview of this book

Table of Contents (17 chapters)
Unity Game Development Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Making audio configurations


For audio configurations, we'll set the volumes for background music, sound effects, and the atmospheric sounds. We will also be setting the speaker mode for the audio output. Let's start off by creating a new C# script and naming it Audio_Config.

Setting the values

The first function that we'll be creating will be used to set the default values for our configurations. Add this function to the script:

public void SetDefaults()
{
  SetBG(1.00f);
  SetSFX(0.80f);
  SetAtm(0.60f);
  SetAudioType("Stereo");
}

In this function, we call the functions that we'll be creating next to set the default values. For the first three functions, we set the volumes for various values. The last function sets the speaker mode to a stereo default.

Configuring the volumes

Now, we'll be adding the functionality to change the volumes. Add these functions to your script:

public void SetBG(float bgVolume)
{
  AudioSource[] audios = GameObject.FindObjectsOfType<AudioSource>();
    
  foreach...