audio source not playing the audio clip

Newbie here!
I have an animator prefab that gets instantiated to which an audio source is added which eventually have an audio clip. I have a script which would play the clip when the prefab is clicked as follows.

public class destroy : MonoBehaviour {

void Start () {

	AudioSource audio = GetComponent<AudioSource>();
}

void Update () {

}
void OnMouseDown(){
	audio.Play ();
	Destroy(this.gameObject);
	}

}

for some reason my clip is not being played. The OnMouseDown() is working though. Please help me. Thanks in alvance :slight_smile:

It looks like the GameObject with the AudioSource on it is being destroyed as soon as Play() is called, so the AudioSource is destroyed before it can finish (or perhaps even start) playing. Try putting the audio source on a different object that isn’t destroyed until after the clip is finished playing.

@abhishekabz004 You should use animation events. With this so you can call a function, in your case to destroy the object, at the end of the animation.