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.
asked Feb 23 '11 at 02:26 AM
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) :
There may be better ways to do it, but this one worked for me..
hope this helps
answered Jun 29 '12 at 09:16 PM