Adding sound effect to response menu
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Adding sound effect to response menu
Hey guys. Is there a way to add a sound effect to response menu choices? I'm making a text game and I'd like to have audio feedback whenever you click a menu choice. Just wondering if there's a way to do this for all choices in game, without having to add it into the Sequencer of every choice node.
Thanks
Thanks
Re: Adding sound effect to response menu
Hi,
Add an Audio Source to the main dialogue UI GameObject. It can be on any GameObject that stays active after you click the response button. The main dialogue UI GameObject is a handy one to choose. Untick the Audio Source's Play On Awake and Loop.
Inspect the response buttons' OnClick() events. Configure them to call the Audio Source's Play() or PlayOneShot() method. If you select Play(), assign an audio clip to the Audio Source. If you select PlayOneShot(), assign an audio clip to the OnClick() event.
Add an Audio Source to the main dialogue UI GameObject. It can be on any GameObject that stays active after you click the response button. The main dialogue UI GameObject is a handy one to choose. Untick the Audio Source's Play On Awake and Loop.
Inspect the response buttons' OnClick() events. Configure them to call the Audio Source's Play() or PlayOneShot() method. If you select Play(), assign an audio clip to the Audio Source. If you select PlayOneShot(), assign an audio clip to the OnClick() event.
-
- Posts: 195
- Joined: Mon Jul 01, 2019 1:21 pm
Re: Adding sound effect to response menu
It works perfectly Thanks!
Re: Adding sound effect to response menu
Glad to help!
Re: Adding sound effect to response menu
Hope it's okay to bump this, wasn't sure if I should create a new topic or not.
Along similar lines, is it possible to add a sound effect when switching between response options? i.e.
I didn't see a field for it on any of the response menu panel game objects - would it have to be done via custom code?
Along similar lines, is it possible to add a sound effect when switching between response options? i.e.
I didn't see a field for it on any of the response menu panel game objects - would it have to be done via custom code?
Re: Adding sound effect to response menu
Hi,
Add an Event Trigger component to each UI Button. Add a Select() event, and configure it to play a sound on an Audio Source. You can put an Audio Source on the Button itself. Untick Play On Awake, and assign the sound you want to play when that Button is switched to.
Add an Event Trigger component to each UI Button. Add a Select() event, and configure it to play a sound on an Audio Source. You can put an Audio Source on the Button itself. Untick Play On Awake, and assign the sound you want to play when that Button is switched to.
Re: Adding sound effect to response menu
Once again, thank you Tony!
Re: Adding sound effect to response menu
Glad to help! You can also try assigning it to Deselect instead of Select if you like that effect better.
Re: Adding sound effect to response menu
Sorry to randomly show up but I was trying to do that and had a problem. If I set the sound playing on Select(), it plays as soon as the response menu opens (since it auto-focuses and selects a button) but if I set it on Deselect(), then it plays after selecting a response, since it disables and thus deselects all the buttons.
Is there a way around that? I think it'd also look nicer if the selected button remained selected after pressing it, and just disable navigation and further presses. Is there a way to do that that works with mouse and keyboard?
Is there a way around that? I think it'd also look nicer if the selected button remained selected after pressing it, and just disable navigation and further presses. Is there a way to do that that works with mouse and keyboard?
Re: Adding sound effect to response menu
Hi,
The solution above is decent -- and, more importantly, relatively easy to implement since it doesn't require any scripting. But it does have the behaviors that you mentioned.
If you were only using mouse, you could use the PointerEnter() event to play the sound, which won't play as soon as the response menu opens. But it will only play when you mouse over a button, not when you navigate to it using keyboard/joystick.
To play sounds for keyboard/joystick navigation, too, you'd want to point the Select() event to a custom script, typically on the response menu GameObject. The script would have two methods:
The solution above is decent -- and, more importantly, relatively easy to implement since it doesn't require any scripting. But it does have the behaviors that you mentioned.
If you were only using mouse, you could use the PointerEnter() event to play the sound, which won't play as soon as the response menu opens. But it will only play when you mouse over a button, not when you navigate to it using keyboard/joystick.
To play sounds for keyboard/joystick navigation, too, you'd want to point the Select() event to a custom script, typically on the response menu GameObject. The script would have two methods:
- PlayNavigationSound: Plays the navigation sound unless a bool variable has been set true. Point the Select() event to this method.
- OnEnable: (Invoked when the response menu is opened.) Sets the bool variable true for one frame, then sets it false.
How would you want this to work? Normally, as soon as you click a response button, the response menu disappears.