- Home /
Changing the audio on key press! Help
I am trying to make it so that always the audio is the "breathing walking" sound and when i press sprint button then the audio is "breathing running".
I tried using audio.Play and Input.GetButton but it doesn't work.
Comment
Answer by Riebulka · Mar 29, 2013 at 08:35 PM
function Update(){
if(Input.KeyDown("shift")){
audio.Play
}
if(Input.KeyUp("shift")){
audio.Stop
}
}
but i want to have the 1st sound playing then change to the 2nd one when i hit left shift
Answer by sparkzbarca · Mar 30, 2013 at 04:05 PM
AudioSources[] audioClips = GetComponents<AudioSource>();
bool Sprinting = false;
if (input.getbutton("sprint"){
sprinting = true
}
if(sprinting){
audioClips[0].stop;
//now do a duration check
//so you know when to play
//the clip again. if so
audioClips[1].play;
}
getcomponents(); gets all audiosources attached as an array;
you can then access each audio source individually to stop and start various ones