On Mouse Click Play Sound

hello I have developed a script to play a sound when the mouse is clicked. I have attached that script to an empty game object with an audio source with the sound that I want to play. However when I begin the game the sound plays and when I click nothing happens. I will post the script below and if anyone could help me that would be awesome. Thanks

var sound : AudioClip;

function Update () {

if (Input.GetMouseButtonDown(0)) {

GetComponent.<AudioSource>().PlayOneShot (sound);


If you’ve attached the audio clip to the source, you need to do:


if you use: PlayOneShot(yourClipName);
you need to pass the clip to the script, not the audio source.