Unity 3D AudioListener Master Volume Control

While developing, I like to listen to music.  However it poses a problem as I test and retest my game, which of course has audio of it’s own.  Rather than muting the game all together, I figured I’d just turn it’s volume down.

Here’s a really quick script for controlling the master volume in Unity 3D’s AudioListener.  Adjust the value of the currentVolume variable between 0 (quiet) and 10 (loud).  This will occur on the Start function.  Move it into Update or LateUpdate if you want control over it after the scene load.

/* Written by Cassius Adams for the Super Space Trooper video game. http://www.SuperSpaceTrooper.com */
var currentVolume : float = 5; // Adjust between 0 and 10
function Start () {
	AudioListener.volume = currentVolume * 0.1;
}
Posted in Javascript JS, Unity 3D, Video Game Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>