Page 1 of 1

Continue Button Sound Effect

Posted: Sun Jan 30, 2022 12:00 pm
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.:?:

Re: Continue Button Sound Effect

Posted: Sun Jan 30, 2022 2:06 pm
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.

Re: Continue Button Sound Effect

Posted: Sun Jan 30, 2022 6:55 pm
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:

Re: Continue Button Sound Effect

Posted: Sun Jan 30, 2022 9:17 pm
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.

Re: Continue Button Sound Effect

Posted: Sun Jan 30, 2022 9:42 pm
by PayasoPrince
I will review this and follow up! 8-)

Re: Continue Button Sound Effect

Posted: Mon Jan 31, 2022 4:21 pm
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? :?

Re: Continue Button Sound Effect

Posted: Mon Jan 31, 2022 4:34 pm
by Tony Li
Hi,

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