play sound on click

I am trying to play a sound when a button is clicked but it doesn’t work.
I have tried both public AudioClip Miss; and public UnityEngine.AudioClip Miss; and latter on I say audio.PlayOneShot(Miss);

I also Selected the audio file and yet when I click in game it says “MissingComponentException There is no AudioSource attached to the GLADIUS game object, but a script is trying to access it.
You probably need to add a AudioSource to the game object GLADIUS. Or your script needs to check if the component is attached before using it.”

AS Unity says, you don’t have Audiosource in your scene. Without an audiosource, your game cannot read/play a sound peacefully.

To read your audioclip, audio.PlayOneShot( yourAudioclip) can work but you need to do this on your object at start before :

	public AudioClip myclip;
	
	// Use this for initialization
	void Start ()
	{
		this.gameObject.AddComponent<AudioSource>();
		this.GetComponent<AudioSource>().clip = myclip;
		this.GetComponent<AudioSource>().Play();
	}

I invite you to read this documentation about AudioSource and AudioClip

P.S : You need to have an AudioListener in your scene (your camera have one per default)

You can use following Unity editor extenstion for buttons click sound management: GitHub - nubick/unity-button-sounds-editor: Editor extension for Unity game engine. It helps to assign AudioClip to buttons and to play sounds by button clicks.