- Home /
Audio playing problem
Hello guys! My player movement script is almost done, just going to add the audio depending on movement. I have the resources already, but I can't figure out how to play them normally. Can somebody suggest what I should be using? Here is a part of my script:
function Update ()
{
if(Input.GetKey(KeyCode.W))
audio1.play();
}
I'm guessing it's because it starts the audio in every frame because of Update, causing the audio to be stuck in the first second. So, how do I fix this? Thank you in advance.
Answer by Key_Less · Apr 08, 2014 at 05:29 PM
You can use the audio source's 'isPlaying' variable to see if the clip is already playing, that way you can preventing it from starting again.
if(Input.GetKey(KeyCode.W))
{
if(audio1.isPlaying == false)
audio1.Play();
}
Your answer
Follow this Question
Related Questions
Audio not playing... 2 Answers
Audio.Play() not showing up 1 Answer
How do I play audio source on Maximize on Play / Audio Source wont play on Maximize 0 Answers
Play next song 1 Answer
[NoBraves] Sound makes lag 1 Answer