Playing Dialogue on Trigger Enter without overlapping sound

Hello all, I’m a novice unity editor and I am trying to set up some game play where when the player enters a space it plays an audio file. I have successfully done this with this code.

// plays audio on collision

var myClip : AudioClip;

function OnTriggerEnter(){

audio.PlayOneShot(myClip);

}

However I’m now running into the problem where the sound will be played over and over again if the player happens to run into the same object. This creates the problem of multiple play backs of dialogue going on at once. As a noob to javascript and unity… I can’t figure out how to set up the if statement… or something else so that only one playback will be going on at a time.

Your help is much appreciated. Thanks.

You can add this script to your trigger to play your sound one time in the scene:

function OnTriggerExit (other : Collider) {
if (other.CompareTag ("Player"))
Destroy();
}

I hope it works.