In the class PlayerControl I have this

if (Input.GetKey("space")) 

In my soundmanager I have this

   public void PlayBleep()
    if (!audio.isPlaying) {

At the moment I am getting the sound like 10 times each time I press space creating horrible soundeffects. How could I get it not to play until the sound has finished?


1 Answer 1


PlayOneShot does not alter isPlaying. See here. So isPlaying will always be false.

A simple fix is to change your input to only trigger once. Instead of Input.GetKey("space") you can use Input.GetKeyDown("space").

You can alternatively add your own flag for when the weapon is active. This additional flag would likely be useful for the animation and other time delays to keep the sword from swinging too fast.

  • \$\begingroup\$ Yeah thats what i did, using a flag. So i guess its a bug? \$\endgroup\$
    – Daarwin
    Oct 12, 2013 at 15:22
  • \$\begingroup\$ See my edited answer. \$\endgroup\$
    – House
    Oct 12, 2013 at 16:25
  • \$\begingroup\$ You could also use a coroutine. Basically at the start of the coroutine set a local bool (playingSound) to true, then use play one shot, do a yield return wait sound.length, and finally set your bool back to false. This way you only trigger the coroutine once and it will just ignore all other play one shot calls. \$\endgroup\$ Oct 13, 2013 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .