Last active
January 9, 2018 12:00
-
-
Save paulhayes/180d567fb8f27327c98159ee4ba55bc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class SoundDelayRepeat : MonoBehaviour | |
| { | |
| private AudioSource audioSource; | |
| private float lastPlay; | |
| public float firstTimeDelay; | |
| public float timeInbetweenSound; | |
| void Start () | |
| { | |
| audioSource = GetComponent<AudioSource>(); | |
| StartCoroutine( PlayLoop() ); | |
| } | |
| IEnumerator PlayLoop () | |
| { | |
| yield return new WaitForSeconds(firstTimeDelay); | |
| audioSource.Play(); | |
| while(true){ | |
| yield return new WaitForSeconds(timeInbetweenSound); | |
| audioSource.Play(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class SoundDelayRepeat : MonoBehaviour { | |
| private AudioSource audioSource; | |
| private float lastPlay; | |
| public float firstTimeDelay; | |
| public float timeInbetweenSound; | |
| void Start () | |
| { | |
| audioSource = GetComponent<AudioSource>(); | |
| lastPlay = firstTimeDelay - timeInbetweenSound; | |
| } | |
| void Update () | |
| { | |
| if (Time.time > lastPlay + timeInbetweenSound) { | |
| timeInbetweenSound = Time.time; | |
| audioSource.Play(); | |
| lastPlay = Time.time; | |
| } | |
| } | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reworked with differing initial delay