Play Audio OnTriggerEnter then loop

I was wondering if anyone knew how to start playing audio, then loop it. What I have so far is just a PlayOneShot, but I’m not familiar with how I would go about writing a script that checks to see if the audio has played in it’s entirety, then play the audio again and again in a loop.

Here’s the PlayOneShot script, using a Trigger to play the audio.

var Sound : AudioClip;

private var hasPlayed = false;

function OnTriggerEnter(){
        hasPlayed = true;

Does anyone know of a way to play the audio in a loop after the whole thing has played?
Using the “Loop” check box on the audio source won’t work obviously, since PlayOneShot cancels out that function.

Don’t use PlayOneShot. Try using

//put in update function and also take out the playoneshot
if (!audio.isPlaying && hasPlayed)
   audio.PlayOneShot (sound);

You could use the loop checkbox on the AudioSource, but uncheck “Play on start”. Then, in your OnTriggerEnter, just do AudioSource.Play(); In OnTriggerExit(), do AudioSource.Stop(); (assuming you want the sound to stop when the trigger is exited).