For example, if you have an explosion effect, the audio should play at the point of the explosion. In some cases, we need to play audio at a given place. StartCoroutine('Delaythis') // Start Coroutine for delay
You can add your required condition to the script.Īud=GetComponent() //get the audio source component Follow the steps below to play the audio after a time delay using script. In the below script, we will get the AudioSource component and play the audio when required using AudioSource.Play().
In most of the cases we need to play an audio in response to some actions like jump, hurt or attack. Check “Play On Awake” to play the audio when the scene loads.Drag and drop your audio file to the AudioClip dialog box under AudioSource in the inspector window.Select the empty game object and go to the inspector window.Create an empty game object in the hierarchy window, by clicking + sign>Create Empty.
You can play an audio during the start of the scene by setting the “Play on Awake” parameter on your AudioSource.