Page 1 of 1

Response buttons and AudioClip

Posted: Sun Mar 27, 2022 2:39 am
by stansison
This is similar to the topic https://www.pixelcrushers.com/phpbb/vie ... nse#p15392

Hello Tony,

I wish to play a sound when the response button is clicked. I followed along the previous post and the sounds works, but the response button is no longer catching the onclick event and the response is not caught. I added an OnClick event to play the audioSource on the Button Component.

My Response panel uses the option to automatically create buttons and the Response template button has the component StandardUI Response Button. It seems one

Am I missing a step?

Re: Response buttons and AudioClip

Posted: Sun Mar 27, 2022 4:26 am
by stansison
StandardUIResposnseButton has this at the start

if (button != null && button.onClick.GetPersistentEventCount() == 0)
{
button.onClick.AddListener(OnClick);
}

Is there anything to watch out for if I remove the check?

Re: Response buttons and AudioClip

Posted: Sun Mar 27, 2022 9:04 am
by Tony Li
Hi,

No need to remove the check. Just configure your Button's OnClick() UnityEvent to also call its StandardUIResponseButton.OnClick method.

Re: Response buttons and AudioClip

Posted: Sun Mar 27, 2022 10:43 pm
by stansison
Thank you for the guidance Tony!

Re: Response buttons and AudioClip

Posted: Mon Mar 28, 2022 8:38 am
by Tony Li
Glad to help!