- Home /
Any Idea why my Explosion sound is NOT playing ?
I am working on a game shooting alien spacecraft, my script for destroying them is working fine but the sound is not playing upon the collision. The wav file has been converted to 2D and is attached to the script and an audio source which is attached to the object I want to destroy. Here is my script:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class collisionTest : MonoBehaviour {
public AudioClip Explosion2;
void OnCollisionEnter (Collision other)
{
Destroy(this.gameObject);
Destroy(other.gameObject);
}
void OnCollisionEnter(){
audio.PlayOneShot(Explosion2,1.0F);
}
}
I am not getting any warnings or errors upon pressing play. I am stumped.
@ahaykal Thank you. I fixed it and got it to work.
Glad you got a solution for your problem, but please take care to post comments as comments and not answers, $$anonymous$$eith (I converted it for you).
Could you please tick it as an answer so it could be closed :) Thank you and glad it worked!
Answer by ahaykal · Jun 01, 2013 at 12:51 PM
Well I think it is because you are destroying the Object and then you want to play the sound. Try not destroying it and then play the sound.
Also increase the max distance for the audio, it might be it's not in the range of the audio listener.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103328im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Destroy object then remake object 1 Answer
How to call(start play) Sound attached to a gameObject by destroing other gameObject? 1 Answer
I need help about audio.PlayOneShot!! 1 Answer
OnCollisionEnter still called when disabled, and destroy sets enabled to false. 1 Answer
Getting audio.PlayOneShot to work 2 Answers