- Home /
Audio sync with explosions
I was following one of the live training PIT: Cinematic and trying to figure out how to get the explosion audio to sync with the script. There is a 3 sec delay from when character starts walking until the explosion(visual) but the explosion(audio) plays as soon as "play" button is pressed. I have tried putting the listener on the car, the character and the camera. I have tried switching play on awake to on and off. In the off position, no sound is played. Not too familiar with scripting but I tried adding a pub var to a script that instantiates and regulates(time delay scale) the explosion but I am not getting anywhere. Here is the script:
using UnityEngine; using System.Collections;
public class ExplosionCar : MonoBehaviour {
public GameObject explosion;
public AudioClip nukeIt;
// Use this for initialization
void Start () {
Invoke ("explode", 3f);
Invoke ("nuke", 3f);
}
void explode(){
Instantiate (explosion, transform.position, Quaternion.identity);
Destroy (this.gameObject);
}
void nuke(){
//not sure what I need to put in here. Have tried
audio (AudioClip.nukeIt);
Ok, so I changed the code in the script. Got rid of the nuke function and the nukeIt var. Did some research and now I have this:
using UnityEngine; using System.Collections;
[RequireComponent(typeof(AudioSource))] public class ExplosionCar : $$anonymous$$onoBehaviour {
public GameObject explosion;
// Use this for initialization
void Start () {
Invoke ("explode", 3f);
audio.Play();
audio.PlayDelayed(5f);
}
void explode(){
Instantiate (explosion, transform.position, Quaternion.identity);
Destroy (this.gameObject);
}
}
Only problem now is volume is too low. I have checked it in the inspector and even tried making sure it was set to 1 in the script, to no avail. Still not sure what the problem is.
Answer by hypnoticmeteor · Jan 10, 2015 at 01:27 PM
If you think that you have done everything to increase the audio and it did not become high.
Audio Source is very far from the listener.(Add an audio source to the main camera and play the sound there)
The audio was recorded at a low volume.
//play audio on main camera generally where Audio Listener is present
Camera.main.audio.playOneShot(nukeIt)
I figured out the volume problem part of it. I "fiddled" with a few things and realized that the audio source was a 3D sound clip. DUH! Changed it to 2D and fixed that problem. As far as the ti$$anonymous$$g is concerned, I think it might be a latency issue. I am using the on-board sound processor and I am guessing this might be what is wrong. I have a card installed but I don't use it to save on processing power of my computer. Will try it and see if that fixes it. Thanks for all the help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180026im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
AudioClip Precise Timing and Delay 1 Answer
Audio loop after time 2 Answers
audio.clip.GetData() returns no data. 0 Answers
Keep playing audio on android even if screen dim or sleep 0 Answers
Stopping audio source without stopping oneshot clips 0 Answers