How to play multiple audio clips in a row?

Hi here’s what I want to do. I have a scene where I want my script to loop through multiply audio clips in a row that I assign via the inspector. I’m currently using this script(Script1) to play the audio clip thats assigned to the audio source attached to my game object and then assign the next audio clip once the first one ends and Im using the yield WaitForSeconds to make sure it plays through the entire audio clip before assigning the new one to the audio source. But this isn’t what I want so I modified the script(Script2) so that it will loop through 3 audio clips, but it won’t work at all and the only error that displays is this one: Script error (audio): Update() can not be a coroutine. Please help! Thanks (:

Script1

#pragma strict
@script RequireComponent(AudioSource)

public var soundClip1 : AudioClip;

	// Play default sound
	function Start()
	{
			audio.Play();
			// Wait for the audio to have finished
			yield WaitForSeconds (audio.clip.length);
			// Assign the other clip and play its
			audio.clip = soundClip1;
			audio.Play();
	}

Script2

#pragma strict
@script RequireComponent(AudioSource)

public var soundClip1 : AudioClip;
public var soundClip2 : AudioClip;
public var soundClip3 : AudioClip;
	// Play default sound
	function Update ()
	{
	
		if(Input.GetKey("m")) {
			audio.Play();
			// Wait for the audio to have finished
			yield WaitForSeconds (audio.clip.length);
			// Assign the other clip and play its
			audio.clip = soundClip1;
			audio.Play();
			
		}
		else if(Input.GetKey("m")) {
		
			audio.clip = soundClip2;
			audio.Play();
			yield WaitForSeconds (audio.clip.length);
			
		}
	}

“Update() can not be a coroutine” means that you cannot call WaitForSeconds into the Update() method.

So I suggest you to do the following code if you want to keep the same logic :

#pragma strict
@script RequireComponent(AudioSource)
 
public var soundClips : AudioClip[3];

private var musicNumber:int = 0;
private var playNextMusic:boolean = true;
    
// Play default sound
function Update ()
{
    if(Input.GetKey("m")) {
        if (playNextMusic) PlayTheNextMusic();
    }
}

function PlayTheNextMusic() {
    playNextMusic = false;
    audio.clip = soundClips[musicNumber];
    audio.Play();
    yield WaitForSeconds (audio.clip.length);
    playNextMusic = true;
    ++musicNumber;
    if (musicNumber == AudioClip.Length) musicNumber = 0; // I'm not sure if it is Length or length here...
}

“I don’t know why the code above would not work.”

 if (musicNumber == AudioClip.Length) musicNumber = 0;

should be

 if (musicNumber == soundClips.Length) musicNumber = 0;

would be my guess at first glance.