I am trying to add sound effects to my game and have them playing, yet they are really quiet when compared to my background music.
The audio source is attached to my game control object, which also has the Audio listener attached to it. I have my background music playing from the audio source, then the Audio Clips use the same audio source.
The code is:
private var thisAudio : AudioSource;
var fire : AudioClip;
function Start()
{
audio.Play();
thisAudio = audio;
}
function Update()
{
if(Input.GetButtonDown("Fire2"))
{
playSound(fire, 1.0);
}
}
function playSound(sound : AudioClip, playLength : float)
{
thisAudio.PlayOneShot(sound, playLength);
}
To increase the volume of your sounds, you could do either of these:
Change your sound effects to be stereo sounds (non-3D sounds). This makes them not vary in volume depending on distance. This might not be the best option if your sounds are coming from an object far away.
Increase the audio source volume in the Inspector (make sure you increase the max volume also). This would be the best option of the two.
Another option could be to lower the background music volume - you could use what I said above to increase the volume, but in the opposite direction (to something like 0.25).
// create sample array
float[] clipSampleData = new float[inAudioClip.samples];
// fill sample array
inAudioClip.GetData(clipSampleData, 0);
// for each samples
for (int s = 0; s < clipSampleData.Length; s++)
{
// increase sample volume
clipSampleData <strike>= clipSampleData ~~* multiplicationFactor; // to multiply the sound by 2 set "multiplicationFacteur = 2f;"~~</strike>
}
// save samples in audio clip inAudioClip.SetData(clipSampleData, 0); // the volume of inAudioClip should be higher
Thanks, this worked for me. However, I had to change this: float[] clipSampleData = new float[clip.samples * clip.channels];
The Maximum Volume is a Audio Source component property. See this page: http://unity3d.com/support/documentation/Components/class-AudioSource.html
– BinaryCavemanAnother option could be to lower the background music volume - you could use what I said above to increase the volume, but in the opposite direction (to something like 0.25).
– BinaryCavemanNo-one really explained this: The maximum volume is 1.0, that's why setting it to 100 made no difference.
– Nition