A
A
Almost2020-05-08 11:22:55
Unity
Almost, 2020-05-08 11:22:55

How to catch a click on any button in Unity?

How to catch clicking on any button on the canvas?
It is necessary to hang the same sound on pressing any button, but buttons can be removed / added to the canvas in large numbers. Can I somehow catch pressing any button and hang up a sound call there?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Almost, 2020-05-09
@Almost

Made through eventSystem.RaycastAll, I get objects, if there is a button component, then sound occurs. Failed to deal with eventSystem.currentSelectedGameObject.

G
GavriKos, 2020-05-08
@GavriKos

Check in which thread the eventSystem.currentSelectedGameObject is updated. If it has changed and meets the requirements (for example, it has a button. Or you can compare by tags or something else), then play the sound.

F
freeExec, 2020-05-08
@freeExec

You make your own class MySoundButton, hang it on all the buttons you create, and play the sound on click in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question