I had a whole bunch of audio sources with carefully calculated rolloffs that wre fine in 2.5 but collapsed as soon as I installed 2.6 and all of them played at once in the Editor and in the builds. It was a cacophony as soon as I hit “Play”.
I reported the issue to Unity. Please do the same.
I have used a script from the Wiki I had anyway because the standard rolloff wasn’t working very well for what I wanted to do with some of my sources but now I use the script for all of them as the built in rolloff seems to have died with 2.6. But honestly the Wiki script is working better anyway.
Here you go, it’s called ModifyAudioSource. I’m sorry I don’t know how people attach scripts correctly but copy and paste into Unitron and hopefully it will work. I didn’t write it but I’m very grateful to whomever did:
// helps to automatically link the first attached instance of this script
// to an Audio Source, if no Audio Sources were present
@script RequireComponent(AudioSource)
// also helps to automatically link the Audio Listener
@script ExecuteInEditMode()
var audioSource : AudioSource;
var audioListener : Transform;
var volume : float = 1;
var minVolume : float = 0;
var maxVolume : float = 1;
var rolloffFactor : float = 1;
var rolloffThreshold : float = 1;
var ignoreDistance = false;
private var loudness : float;
private var minLoudness;
private var maxLoudness;
private var loudnessExponent = Mathf.Log(Mathf.Sqrt(10), 2);
function Volume ()
{return loudness;}
function Volume (value)
{
// volume values outside 0-1 mean nothing in Unity
volume = Mathf.Clamp01(value);
loudness = Mathf.Pow(volume, loudnessExponent);
if (audioSource ignoreDistance)
audioSource.volume = Mathf.Clamp(loudness, minLoudness, maxLoudness);
}
function MinVolume ()
{return minLoudness;}
function MinVolume (value)
{
// volume values less than 0 mean nothing in Unity
// ensure minVolume is not greater than maxVolume;
minVolume = Mathf.Clamp(value, 0, maxVolume);
minLoudness = Mathf.Pow(minVolume, loudnessExponent);
}
function MaxVolume ()
{return maxLoudness;}
function MaxVolume (value)
{
// ensure maxVolume is not less than minVolume;
// volume values greater than 1 mean nothing in Unity
maxVolume = Mathf.Clamp(value, minVolume, 1);
maxLoudness = Mathf.Pow(maxVolume, loudnessExponent);
}
private var rolloffExponent;
function RolloffFactor ()
{return rolloffExponent;}
function RolloffFactor (value)
{
// Negative values don’t make sense for this
rolloffFactor = Mathf.Max(value, 0);
rolloffExponent = Mathf.Log(.5, (1 / rolloffFactor + 1));
}
// no need for a “getter”; use rolloffThreshold directly
function RolloffThreshold (value)
{
// Negative values don’t make sense for this
rolloffThreshold = Mathf.Max(value, 0);
}
var thisTransform : Transform;
function Start()
{
// If there is only one Audio Source attached to this game object,
// and there are no other instances of this script attached,
// automatically link this script to the Audio Source.
if (GetComponents(AudioSource).Length < 2
GetComponents(typeof this).Length < 2)
audioSource = audio;
if (!audioListener)
{
var listenerComponent : Component = FindObjectOfType(AudioListener);
if (listenerComponent)
audioListener = listenerComponent.gameObject.transform;
}
// These properties are not useful;
// initializing them this way keeps this script as tidy as possible.
if (audioSource)
{
audioSource.minVolume = 0;
audioSource.maxVolume = 1;
audioSource.rolloffFactor = 0;
}
thisTransform = transform;
Volume(volume);
MinVolume(minVolume);
MaxVolume(maxVolume);
RolloffFactor(rolloffFactor);
// Change values in the Editor (during Play Mode); get results.
if (Application.isEditor Application.isPlaying)
StartCoroutine(“RefreshProperties”);
}
// Using OnDrawGizmos() would be a performance hit
// in the Editor, given several properties to update.
function RefreshProperties ()
{
while (true)
{
Volume(volume);
yield;
MinVolume(minVolume);
yield;
MaxVolume(maxVolume);
yield;
RolloffFactor(rolloffFactor);
yield;
}
}
function Update ()
{
if (Application.isPlaying audioSource audioListener (ignoreDistance == false))
{
var distanceToListener = Vector3.Distance(thisTransform.position, audioListener.position);
var rolloffBase = distanceToListener / rolloffThreshold;
var positionalVolume = Mathf.Pow(rolloffBase, rolloffExponent) * loudness;
audioSource.volume = Mathf.Clamp(positionalVolume, minLoudness, maxLoudness);
}
}