Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

How to play multiple audio clips in a row?

$
0
0
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); } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>