I have a problem, after one audio I immediately have another, how do I make the audio play every 30 seconds. Thanks!!! Code. I try to use WaitForSeconds(6) but it wait 6 sec only before first traack
using UnityEngine;
using System.Collections;
public class RandomAudio : MonoBehaviour
{
public AudioClip[] soundtrack;
// Use this for initialization
void Start()
{
if (!GetComponent<AudioSource>().playOnAwake)
{
GetComponent<AudioSource>().clip = soundtrack[Random.Range(0, soundtrack.Length)];
GetComponent<AudioSource>().Play();
}
}
// Update is called once per frame
void Update()
{
if (!GetComponent<AudioSource>().isPlaying)
{
GetComponent<AudioSource>().clip = soundtrack[Random.Range(0, soundtrack.Length)];
GetComponent<AudioSource>().Play();
}
}
}