click sound on all GUI.Button calls


i got this whole interface done with UnityGUI using GUI.Button and GUILayout.Button.

i want every click on everybuttong in the game to make a sound. It's not a property of the skin i'm using.

how can i do it? is there a way to override the GUI.Button function or something?

i'm coding in C#

UnityGUI is for visuals only. If you want sound effects, you'll need to code them in manually using an AudioSource.

Adding on to what Mike said (albeit a little more in-depth), is that you could, instead of calling GUI.Button, call your own function like this:

// Create a wrapper function for GUI.Button + Sound.
// You can include alternate method headers if you want
// to use a Texture or GUIStyle instead of a string.
void ButtonWithSound(Rect position, string text)
     GUI.Button(position, text);
     // Play sound here

void OnGUI()
     ButtonWithSound(new Rect(0, 0, 100, 100), "My Button");
     ButtonWithSound(new Rect(200, 200, 100, 100), "My Second Button");
     // Call your GUI/Sound function(s) here.

Just make your own static button function, which makes a sound and calls GUI.Button