Best way to change looping sound

I’m adding sound to my game and I want to use 4 soundclips from the asset store to it. It’s a series where the intensity of the sound grows as the game progresses.

I have already added one AudioSource to the object and am using audio.Play() and audio.loop=true in the code. But I’m wondering how to chance the sounds from one to the other. I know I can add extra scripts to handle this, but I think there should be an easier way from the main script where the whole thing is running from?

You could solve this issue in different ways.

  1. Remove the audio clip you added to audio source and here’s a simple script to add multiple audio clips. You don’t need to turn looping on, as the script will automatically loop audios one after another.

    public class MyCustomAudioScript : MonoBehaviour

     public AudioClip[] _myClip;
     private int i=0;
     private float nextClip=0f;
     void Update()
     	if(Time.time > nextClip)
     		nextClip = Time.time + audio.clip.length;
     void SetAndPlayAudio()
     	audio.clip = _myClip*;*
  • }*
    2. Or try combining all of your audio clips usings any external Audio software to make it as a single clip. :slight_smile:

It is possible to simply change the looped audio clips with another clip. Important in the script for this is a direct change in the audio source clip and a renewed call function AudioSource.Play () necessary. So changes and directly play the new clip in the loop.
Make sure that AudioSource.clip and AudioSource.Play () is called only once.