Audio loop after time

Ok, so i have a simple code:

Audio.clip = footstep;
Audio.loop = true;

Now, this starts the audio, and when it ends, it restarts it, but what i want is the audio to start, and after 3 seconds, start again (So before your audioclip is over, start a new one over it) The end of every audio clip has a fade out effect made in sony vegas, so when i get the script i’d like to have (after 3 seconds, restart but leave old one playing until its ended) it looks like the one is fading out while the other one plays.

This code could be complicated, so //messages are helpfull

Hi theFTWnetwork,

  1. I think you will need 2 audio
  2. Place them at the same spot
  3. Have each one loaded with the same
    sound clip
  4. Start one of them first, using the
    code you show above
  5. Start the second one but use yield
    WaitForSeconds (3); before the

Although I would personally use a clean looping clip of footsteps and use code to fade the sound out when required.

Hope it helps.


I know this topic is old but I found a simpler way to solve your problem. I wanted an enemy to growl in intervals, but not have the growl be looped back to back. My solution was to use these two lines in Update():

if(Time.time % 3f > 2.9f)
	audio.Play ();

It doesn’t play in exact intervals (like exactly 3 seconds) but it loops pretty reliably. I’d recommend putting in Debug.Log(Time.time % 3f); to see how often it repeats, then change the two numbers to an interval closer to what you want. To avoid the sound clip stuttering and overlapping, make the second float very close to the first (About 0.1 or less of a difference)