|
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.
(comments are locked)
|
|
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.
And then call
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).
(comments are locked)
|
|
uhmm got a little problem where to place the audio.PlayOneShot(audio.clip); ??? please help this sad guest
(comments are locked)
|
(comments are locked)
|
|
uhm really thanks but... i got a error and i dont know what to do can you help me ?
what to do ? here's what I did: var model : GameObject; var track : AudioClip; function OnGUI () { //background box GUI.Box (Rect (10,130,100,90), "Sounds"); //Make first button if (GUI.Button (Rect(20,160,80,20), "Go")){ audio.loop = false; } //Make second button if (GUI.Button (Rect(20,190,80,20), "Stop")){ audio.Stop(); } } I added a component which is Audio Source to the main camera, dragged my mp3 to the track variable and I also dragged this one to the AudioClip slot. It worked but my editor log returns this message: MissingComponentException: There is no 'AudioSource' attached to the "Main Camera" game object, but a script is trying to access it. You probably need to add a AudioSource to the game object "Main Camera". Or your script needs to check if the component is attached before using it.
Dec 25 '11 at 05:19 PM
charnew
(comments are locked)
|
(comments are locked)
|
