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. 
You destroy the gameobject (with the attached audio) before it gets to play…
And yeah you only need one OnCollisionEnter function 
Why do you have 2 OnCollisionEnter? You must remove the second and move PlayOneShot in the first.
I got rid of the 2nd OnCollisionEnter and nested the audio.PlayOneShot within the Destroy brackets. I am now getting this caution:
Can not play a disabled audio source
UnityEngine.AudioSource:PlayOneShot(AudioClip, Single)
Because as willemsenzo notified to you, you’re destroying the object so the audiosource cannot play. You could probably workaround this by moving Destroy into a coroutine where you yield until audio has finished playing to be called after PlayOneShot (and destroy the collider on collision so you will have one only collision).
I Thank You for your answers, but I am new to programming and I don’t know how to do a coroutine. I apologize for being dense but could some show me some examples, please.
A coroutine allows you to put a delay in the execution of code. In this case it’s useful to delay the Destroy function because you want to play a sound when you destroy the object but you can’t make the object play a sound if the object itself doesn’t exist anymore.
This is how you can make a coroutine:
IEnumerator WaitAndDestroy()
{
audio.PlayOneShot(Explosion);
yield return new WaitForSeconds(3.0f); //float time in seconds
}
You call the function with:
StartCoroutine(WaitAndDestroy());
You can call this function from the OnCollisionEnter function so that before you destroy the object, you first play the sound, wait for a couple of seconds and eventually when that’s done you destroy the object. Your code could look something like this:
void OnCollisionEnter (Collision other)
{
StartCoroutine(WaitAndDestroy);
Destroy(this.gameObject);
Destroy(other.gameObject);
}
By the way, the scripting reference is extremely useful. Unity - Scripting API: MonoBehaviour.StartCoroutine
Thank You for the example very much. I did look at the scripting reference after Skared mentioned it. I apologize again for being dense, I’ve been pulling an all nighter. Thank You All again very much.
No problem and good luck. If you need help you know where to ask 
I modified the script and am not getting any warnings or errors again but the ships are still being destroyed on collision and no sound is playing.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class collisionTest : MonoBehaviour
{
public AudioClip Explosion2;
IEnumerator WaitAndDestroy(){
audio.PlayOneShot(Explosion2);
yield return new WaitForSeconds(3.0f);//float time in seconds adjustable
}
void OnCollisionEnter (Collision other)
{
StartCoroutine(WaitAndDestroy());
Destroy(this.gameObject);
Destroy(other.gameObject);
}
}
Move Destroy(this.gameObject) to WaitAndDestroy after the yield line, else as I already said the audio source will not play because the object has been already destroyed.
Also I would change WaitAndDestroy:
IEnumerator WaitAndDestroy()
{
audio.PlayOneShot(Explosion);
while (audio.isPlaying) yield return null;
Destroy(gameObject);
}
I modified the script and still the ships are being destroyed with no wait and no sound. I am still getting no errors or warnings. Thank You all for your help so far.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class collisionTest : MonoBehaviour
{
public AudioClip Explosion2;
IEnumerator WaitAndDestroy(){
audio.PlayOneShot(Explosion2);
while (audio.isPlaying) yield return null;
Destroy(this.gameObject);
/yield return new WaitForSeconds(2.0f);/
}
void OnCollisionEnter (Collision other)
{
StartCoroutine(WaitAndDestroy());
/Destroy(this.gameObject);/
Destroy(other.gameObject);
}
}
Is the other being destroyed? I would out calls into the script, print(“is this here?”"); to see if the functions are even being reached.
yes the projectile is being destroyed on collision with the alien ship.
Did you assign the audio clip?
audio.clip = explosion2?
And did it work? Did you check volume? Also, place a print or debug.log before and after the audio plays. See if the function is passing, if it is seeing if the audio actually has played. Also, I have noticed that if an audio file is set to be 3D, that it can be awfully quiet.
No it did not work, I am playing around with the Detonator Unity package now to try and figure things out. All my sounds I have imported are converted into 2D. The detonator pack is working fine, I have attached the detonator script and sound file to my ship I want to blow up, I have tested it by pressing play and leaving the play on awake boxes checked for the explosion and sound. The explosion effect and sound both play and it destroys the ship, now if I could just figure out how to make it happen at the instant of the projectile colliding with the ship I would be golden.
So did you place prints in the ienumerator to see if it is functioning? Other than that, I don’t have much.
I finally got my explosion effect to work by using a prefab I call hitBox. I made a empty game object and added a box collider to it and checked is trigger, wrote a small script to Instantiate the explosion prefab then placed it over the original collider to Destroy the ship but just slightly bigger to play the effect before destroying the ship, the projectile is moving so fast it is imperceptable. I still have one problem though, the explosion effect only shows at the original ship coordinates and not any of the clones coordinates or if I move the original in any way.