Skip to content

Instantly share code, notes, and snippets.

@SpaceShot
Created February 13, 2015 12:11
Show Gist options
  • Save SpaceShot/889ed6ac6dd444a75986 to your computer and use it in GitHub Desktop.
Save SpaceShot/889ed6ac6dd444a75986 to your computer and use it in GitHub Desktop.
Sample Unity Coroutine that loops a audio clip with a delay between plays
using UnityEngine;
using System.Collections;
public class AudioLoopWithDelay : MonoBehaviour {
public float Delay = 5.0f;
// Use this for initialization
void Start () {
StartCoroutine(YourFunctionName());
}
// Update is called once per frame
void Update () {
}
IEnumerator YourFunctionName()
{
while(true)
{
DoSomething();
yield return new WaitForSeconds(Delay);
}
}
void DoSomething()
{
this.audio.Play ();
}
}
@ryanweirdy
Copy link

This was a big help. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment