- Home /
2 sound for one object on press of diffrent buttons.
hello everyone ,
my querry is as follows: i have an object and i have inserted two audio clips to it .game object is a TANK . on press of key "W" tank audio should play . on click of spacebar it fires so i want to play the firing sound on click of spacebar. i have tried like this:
var tank: AudioClip;
var fire: AudioClip;
function Update() {
if (Input.GetKey(KeyCode.W))
{
audio.PlayOneShot(tank);
}
else if (Input.GetKey(KeyCode.Space))
{
audio.PlayOneShot(fire);
}
else
{
audio.Stop();
}
}
@script RequireComponent(AudioSource)
only problem i am getting here is that fire sound does not play along with tank sound.i want to play firing sound simultaneously while tank sound gets played.
NOTE : i am using audio.Stop(); jus to stop the tank sound instantly .. else the tank audio keeps on playing unless the audio is complete . i am using only 1 audiosource . i hope dats not a boring question. this is my first question to unity n its members. THANX :)
Answer by Jeff-Kesselman · Jun 07, 2014 at 02:54 PM
Unity does not provide the ability to mix two audio tracks through one audio source. If you want to mix the tracks, give each one its own audio source.
Your answer