Hello, I am trying to have a quick sound play when I press a GUI Button Here is the script that I have for the GUI buttons. Is there an easy way to attach a sound to each button.
var model : GameObject;
function OnGUI () {
//background box
GUI.Box (Rect (10,130,100,90), "Sounds");
//Make first button
if (GUI.Button (Rect(20,160,80,20), "Go")){
}
//Make second button
if (GUI.Button (Rect(20,190,80,20), "Stop")){
}
}
It is in fact very simple: All you need to do is attach an AudioSource to the same game object (or any other game object), provide a "slot" for that audio source, e.g.
var audio : AudioSource;
And then call
audio.PlayOneShot(audio.clip);
in your if-blocks. If you want multiple sounds, simply create one game object with relevant audiosources attached for each sound you want to play (and create var audio1 : AudioSource; and so on, or use names that actually will tell you what the sound means).