x


Audio for a toolbar?

Hello. When using a GUI toolbar, how do you play an audio clip when one of the options is selected(I know how to do this for a button, but when I try to put it in for the toolbar, it plays continuously because it is being updated)? Thanks.

more ▼

asked Feb 23 '11 at 02:26 AM

Tyler 2 gravatar image

Tyler 2
1.1k 211 246 264

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You need an AudioSource component, on the same GameObject makes it simpler to manage. Then you need to catch when the selection changes. You can do that by having two variables, one for the previous state, and one for the new state. Whenever the new state is different from the previous, you play the sound and set the previous to match the new.

Pseudo code (UnityScript) :

 function Update () {  if (_previous != _new) {  this.GetComponent(AudioSource).Play();  _previous = _new; } } 

There may be better ways to do it, but this one worked for me..

hope this helps

more ▼

answered Jun 29 '12 at 09:16 PM

CgShady gravatar image

CgShady
103 13 15 22

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1029
x28

asked: Feb 23 '11 at 02:26 AM

Seen: 693 times

Last Updated: Jun 29 '12 at 09:24 PM