Sound Effect for Selection Grid choices

One area in which the Unity GUI is currently a little weak, in my opinion, is audio. I find it pretty easy to work with text and images with it, but it’s more work to bring audio into the picture. It’s not a big deal to type “audio.PlayOneShot()” for Buttons, although it would be very nice to be able to define that clip in a Style or Skin. Selection Grids are a different story, however. Does anyone have a tip for getting a sound effect to play only when making a selection in the grid?

use GUI.changed
(Unity - Scripting API: GUI.changed)

or something like

function Update () {
   if (!selectedgridbutton == selectedgridbutton1) {
       //do something
   }
   selectedgridbutton1 = selectedgridbutton;
}
function OnGUI () {
   selectedgridbutton = GUI.Grid...........
}

Warning it’s not real code just an example :wink:

Thanks!

I completely forgot I had this thread running. What I ended up doing was:

private var objects = new Array();  // a list of all currently available objects
private var objectClicked : String;  // the object that has last been clicked, used for sfx upon selecting an object
var clickSound : GameObject;  // a game object with the click audio clip attached

function Start() {
	objects = ?;  // define what the objects array is here
	object = objects.length + 1;  // make it so no object is selected to begin with
	objectClicked = "";
}

function OnGUI () {
	var utObjects = objects.ToBuiltin(String);  // so you can modify the objects list and make the GUI grid work
	object = GUI.SelectionGrid (Rect (?, ?, ?, ?), object, utObjects);	
	if (object <= utObjects.Length) {
		if (objectClicked != objects[object]) {
			objectClicked = objects[object];
			clickSound.audio.Play();
		}
	}
}