- Home /
 
 
               Question by 
               sanamdehghan · Dec 20, 2011 at 12:42 AM · 
                audiosound effects  
              
 
              Sound effect issues
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
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Zergling103 · Dec 20, 2011 at 01:42 AM
 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;
             
         }
     }
 }
 
              Press the check mark and thumbs up icon by my answer if you feel it warrants it. :)
Your answer