Hi all,
I’m making a board and in one scene a die will be thrown and I want to add a sound effect for that to release the reality of it. However, I want the sound effect plays after some seconds that scene starts to run. How can I do it?
Thanks for your help
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class DelayedAudioSource : MonoBehavior {
public float delayInSeconds = 0;
private float clock = 0;
void Start() {
audio.Stop();
audio.enabled = false;
clock = Time.time;
}
void Update() {
if(Time.time - clock > delayInSeconds) {
audio.enabled = true;
audio.Play();
enabled = false;
}
}
}