- Home /
How to stop an Audio Clip without an Audio Source?
Hello, I want to know how to stop an audio clip that I have played from the code 'audio.playOneShot'. In my project I want to press a key and play an audio file (without making lots of audio sources) and if I press the same key again while the audio clip is playing then stop the audio clip and play it again at the same time.
Can anyone help please? Anything helpful is really appreciated.
Answer by DaveA · Aug 26, 2012 at 06:43 AM
You need one AudioSource, that will be the 'audio' in 'audio.playOneShot' When you press the key, just tell it to stop then play again.
O$$anonymous$$ maybe I need to clear this up a little bit. In my project I have a Speaker gameObject and in this object I want to play music when I press the '$$anonymous$$' key and play a sound effect when I press the 'F1' key, but I want the music's volume to mute and the sound effect to play, then once the sound effect has finished playing the music's volume will unmute.
Hope that explains it a little bit better.
Thank for any help :D
Your answer
Follow this Question
Related Questions
I need help about audio.PlayOneShot!! 1 Answer
Get audio from device... -1 Answers
Help with sound clips [C#] 0 Answers
Play Sound when GUI button is pressed. 7 Answers
Do I have to create an audio source component to play a sound from script? 2 Answers