Search Unity

global button click sound approach

Discussion in 'UGUI & TextMesh Pro' started by Tom163, Jan 18, 2021.

  1. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
    What's the standard approach for having every button clicked emit a button-click sound? I've done some searching and while there are a few overly-complex answers, something as common as that (arguably, on the same level as the built-in hover effect of the UI.Button class) strikes me as something that should have an easy solution.

    I couldn't find it, though, so I'm asking here. A way to a) make every button emit the same sound upon clicking and/or b) different groups of buttons and/or c) every button can make a different sound but there's a configurable default.

    My thought on approaching this would be to create a button prefab that includes everything, or write a few simple scripts that attach to each button and call a global audio source. The later because then I can define the sounds in one place and can be sure that if I change a sound I don't have to go through a thousand buttons and probably miss a couple.

    But almost everyone must have had this issue and found a solution, right? So before I re-invent the wheel...