- Home /
Play 2 audios at the same time?
Hi,
I was trying to add audio for when my character is firing a gun shot, and the problem is that the audio clip I'm playing for the shot starts everytime I click the Fire button (mouse), but it als ENDS the last one, so when you shoot just a bit fast, it makes a horrible sound of audio stopping and beginning again.
In other questions I saw answers about clip.isPlaying, but I don't want to delay the playing of my clip, I want it to sound at the same time (one before, one just after). Can't they overlap?
I tried adding more AudioSource components and putting the same clip on them, and then looping (one shot for each of the AudioSources), but it was for no use...
Any ideas? Thanks a lot!
Answer by FLASHDENMARK · May 27, 2012 at 03:17 PM
Won't something like this work?
var shootSound : AudioClip;
var audioSources : AudioSource[];
private curAudioSource : int;
function Update (){
if(weapon is shooting){
curAudioSource++;
if(curAudioSource > audioSources.length-1)
curAudioSource = 0;
audioSources[curAudioSource].PlayOneShot(shootSound);
}
}
(Not tested code)
This should loop through all of the audioSources in 'audioSources' and play a new sound from a new audioSource everytime you are shooting, resulting in 'overlapping' audioclips. If you put 3 audioSources in the array, it should work smoothly.
Your answer
Follow this Question
Related Questions
Help with sound clips [C#] 0 Answers
Get audio from device... -1 Answers
Random, 3d sound. 1 Answer
Set audio clip to 3D in script 1 Answer
Playing Sound 2 Answers