Continue Button Sound Effect

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Continue Button Sound Effect

Post by PayasoPrince »

Hello,

I've added the following OnClick() event, "PlaySound()" to my Continue button.
Image

Here is what PlaySound() looks like:

Code: Select all

public class ContinueButton : MonoBehaviour
{
    public Sound sound;
    public void PlaySound()
    {
        sound.source.Play();
    }
}
For some reason the sound isn't playing upon pressing continue.:?:
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue Button Sound Effect

Post by Tony Li »

Does the Console contain a warning like "Can not play a disabled audio source"?

The continue button gets deactivated when it's clicked. Try moving the audio source and the script to your Dialogue Panel GameObject. Then hook up the continue button's OnClick() to call the same method, but on the Dialogue Panel.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Continue Button Sound Effect

Post by PayasoPrince »

The console doesn't throw any warnings.

I moved both the audio source and the script to the Dialogue Panel GameObject. Then I hooked it up to the continue buttons OnClick() event. However, the sound still does not play. :(

Just as a sanity check, I made it so I stopped disabling my Continue button and it still would not play. Very strangel... :cry:
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue Button Sound Effect

Post by Tony Li »

Here's an example scene:

DS_ContinueButtonAudioExample_2022-01-30.unitypackage

It doesn't use your Sound script; it's just standard Unity and Dialogue System. But it demonstrates how the continue button can play an audio clip.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Continue Button Sound Effect

Post by PayasoPrince »

I will review this and follow up! 8-)
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Continue Button Sound Effect

Post by PayasoPrince »

I figured out the discrepancy!

I noticed that when I click the button with my actual mouse, OnClick() is called and the sound effect plays. However, I have a "UI Button Key Trigger" on my Continue button and I press a key to Continue.

I'm guessing that using UI Button Key Trigger to hit Continue with a key doesn't call OnClick(). Is there a workaround for this? :?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue Button Sound Effect

Post by Tony Li »

Hi,

Add a Submit event, and configure it to do the same thing.
Post Reply