audio for gui button

I’m trying to play a click sound for a gui button, what’s wrong with my codes?

var clicksound : AudioClip;

var audioSource: AudioSource;

function OnGUI () {

  audioSource.clip = clicksound;


When I went to the Inspector, the slot for AudioSource is there but I cannot drag anything to it.

You say you’re trying to drag an audioclip onto an audiosource? You can’t do that because they’re not the same type.

I don’t think you need to reference an AudioSource, rather you should give the gameobject the component Audiosource and you can store the audioclip as a variable if you have more than one.

Can you see the audioclip variable in the inspector?