audio.IsPlaying dosn't work


I wrote this script that is supposed to play a sound when you click a door. The problem is that it must prevent the sound to play if the player spams the door, but it doesn’t work. When I click the object, no matter if a sound is already playing, it plays it again…
Any help?

#pragma strict
var soundToPlay : AudioClip[];
var knocks : int;
function Start () {


function OnMouseDown () {
		var index : int = Random.Range(0,12);
		audio.clip = soundToPlay[index];
		knocks ++;

Try using Play instead of PlayOneShot.

PlayOneShot was designed for playing the same sound multiple times from the same source, so I imagine there’s some weirdness going on with isPlaying.