Checking if audio PlayClipatPoint already playing?

Is there a way to check if an audio using PlayClipatPoint is already playing and if not play that clip?

Unfortunately, PlayClipAtPoint doesn’t return a reference to the temporary AudioSource it creates, thus we can’t check whether it’s playing. A simple (although ugly) solution is to GameObject.Find an object called “One shot audio” (that’s the name PlayClipAtPoint gives to the temporary game object it creates) - if not found, the clip has finished:

if (!GameObject.Find("One shot audio")){ // if no temporary audio source...
  AudioSource.PlayClipAtPoint(....); // play the sound
}

Besides being inelegant, the sound won’t be played if there are other temporary AudioSources alive.

If you want to play the sound continuously, a better solution is to repeat the sound at the suitable rate:

var sound: AudioClip;

private var tSoundEnd: float;

function Update(){
  if (Time.time > tSoundEnd){ // if previous clip has finished playing...
    AudioSource.PlayClipAtPoint(sound, ...); // play a new one...
    tSoundEnd = Time.time + sound.length; // and calculate time for next
  }
}

Finally, you could create your own PlayClipAtPoint function: it could return a reference to the game object created, and when it became null you would know that the clip wasn’t playing anymore:

public var sound: AudioClip;

private var curTempAudio: GameObject;

function PlayClipAt(clip: AudioClip, pos: Vector3): GameObject; {
  var tempGO = GameObject("TempAudio"); // create the temp object
  tempGO.transform.position = pos; // set its position
  tempGO.AddComponent(AudioSource); // add an audio source
  tempGO.audio.clip = clip; // define the clip
  tempGO.audio.Play(); // start the sound
  Destroy(tempGO, clip.length); // destroy object after clip duration
  return tempGO; // return reference to the temporary GameObject
}

function Update(){
  if (!curTempAudio) curTempAudio = PlayClipAtPoint(sound, transform.position);
}