Listener
(→Instructions) |
(→JavaScript - Listener.js) |
||
Line 17: | Line 17: | ||
var volume : float = 1; | var volume : float = 1; | ||
− | + | private var loudnessExponent = Mathf.Log(Mathf.Sqrt(10), 2); | |
− | + | ||
− | + | ||
− | + | ||
− | private var loudnessExponent = Mathf.Log(Mathf.Sqrt(10), 2); | + | |
function RefreshVolume () | function RefreshVolume () | ||
Line 30: | Line 26: | ||
function Update () | function Update () | ||
− | { | + | {RefreshVolume ();}</javascript> |
− | + |
Revision as of 18:23, 23 April 2009
Author: Jessy
Description
This is a script that replaces the Volume property of the Audio Listener. I feel that its behaves more intuitively than that of the Audio Listener itself. See the page for my Audio script for extensive details. :-D
Instructions
The Volume parameter performs the task that the similarly-named parameter of an Audio Listener was intended to perform.
Performance Mode makes the code execute faster, but the effects of Volume are not automatically updated every frame. You can call the RefreshVolume() function, to make changes only when necessary, from external code.
JavaScript - Listener.js
<javascript>@script RequireComponent(AudioListener)
var volume : float = 1;
private var loudnessExponent = Mathf.Log(Mathf.Sqrt(10), 2);
function RefreshVolume () {audioListener.volume = Mathf.Pow(volume, loudnessExponent);}
function Start () {RefreshVolume ();}
function Update () {RefreshVolume ();}</javascript>