Why does sound attached to gameobject is not playing at desired time?

Hey!
I am having an animator gameobject to which I have attached a sound source.
I need the audio to be played when I click my gameobject.
Here is my code.

public class destroy : MonoBehaviour {

private AudioSource source;

void Update () {

}
void OnMouseDown(){
	
	source = GetComponent<AudioSource>();
	source.Play ();
	
	//source.PlayOneShot ((AudioClip)Resources.Load("BOING_")); 
     }

}

The sound is being played. But the problem is it is getting played well before I click them. To be more precise its being played when the game starts.
Please help me in solving this.
Thanks in advance!! :slight_smile:

Thats because OnMouseDown is called only when you are pressing mouse button. You should do something like this:

private AudioSource source;

 void Update () {
 
 }
 void OnMouseDown(){
     
     source = GetComponent<AudioSource>();
     PlaySound();
}

 void PlaySound(){
     source.Play ();
}