Collision destroy help.

Hey I have two gameObjects that’s going to collide to eachOther I want to how to make one destroy the other on collision. Here is what I got. I’m new to coding. Also there is a error “Play”.

var Hit : GameObject;
var sound : AudioClip;

function OnCollisionEnter (collision : Collision)
{
	if (collision.gameObject.tag == "Destroy");
	Destroy (gameObject);
	Play.AudioClip;


}

highpockets is correct, so there are a few things to consider. Look at the following modes to your code. I also added some debug statements so you could see what is going on.

If this script is attached to a gameObject and I tag my playerController as “Destroy” then I can run the player into the object to activate the collision. The Short sound will play and then the object is destroyed after a short delay in order to allow time for the AudioClip to play. If you want the Object to be destroyed immediately then you will not get any sound because the AudioSource is Destroyed, which is attached to the object just destroyed. So, you’ll need to think about putting the sound intelligence (and perhaps the destroy intelligence as well) into the “Destroy” Object. I’m not sure what you’re trying to do so it’s up to you.

Also see the links to AudioSource Info in the ScriptRef Doc. Unity - Scripting API: AudioSource.clip

Let me know if my rambling makes sense.

var Hit : GameObject;  // this in never used???
var sound : AudioClip;

function OnCollisionEnter(col : Collision)
{
   Debug.Log("ENTER OnCOllisionEnter Collion.gameObject.name ==> " + col.gameObject.name + "  tag ==> " + col.gameObject.tag);
   
    if (col.gameObject.tag == "Destroy")
    {
    		Debug.Log("Destroy gameObject.name ==> " + gameObject.name);
    		Destroy (gameObject, 1);  // destroy object in 1 second to give time for the clip to play.
    }
    		   		
   	// Assign the audio clip and play it
   	// Need to have an audioSource on this object in order for clip to play
   	// NOTE: If you destory the object the AudioSource is also e destroyed so clip will not play.
   	//       So, give time in the above destory call to allow clip to play.
    Debug.Log(" AudioClip is ==> " + sound); 
	audio.clip = sound;
	audio.Play();
  
    Debug.Log("Exit OnCollisionEnter");
}