Turn on and off sound on mouse click C#


I have an object and when you click on it with the mouse the sound will play. I want to be able to turn the sound off when I click on it again.
This is what I have so far:

public AudioClip mySound;

void Start () {

void OnMouseDown ()
	if (Input.GetMouseButtonDown (0))
		GetComponent<AudioSource> ().PlayOneShot (mySound);




all what you need is just like pause button. if you press first time music has to play, if you hit again music has to stop. if so then try this

bool play;

 if (Input.GetMouseButtonDown (0)){
     play = !play;

  // play your music

}else {

// stop your music