- Home /
Question by
Dan Jimenez · Feb 17, 2011 at 10:54 PM ·
guibuttonaudioclip
play an audio clip from a GUI button
Hello I am trying to play an audio clip from a GUI button. The button already plays an animation when pressed. How do I script it to also play the sound. This is the code for my GUI button. Thanks.
function OnGUI () {
if (GUI.Button (Rect (10,130,70,20), "BLUE")) {
animation.Play("car2");
}
}
Comment
Best Answer
Answer by JGeorge · Feb 17, 2011 at 11:03 PM
You will need to make a reference to the audioclip, and the object with the script on it will need to have an audiosource on it.
Then right below the line that says animation,play, I would put audio.playoneshot().