hello. im making a game and im trying to figure out how to do this myself since programmers in my team are inactive. so, sorry if this is a dumb question but i want to know how to add a sound effect to a cursor, because i want to:
add sound effect for normal click.
add sound effect for hovering on buttons.
add sound effect for clicking a button.
ok so, i know now that i have to add an “audio source” to the game object by googling abit.
but further than that, i can’t reach.
to make it more clear, this is my game and i want to add a sound effect to when you click “new game”, and when you hover over “new game”, “continue”, “options”, “credits”, and “quit”.
if you want to help me further than just adding the sound effect to the cursor it would be highly appreciated.
Drag your sound clip into ‘AudioClip’ and make sure ‘Play On Awake’ is not checked.
Go to your UI Button:
Click the + under On Click. You’ll get one of these:
Drag the button object itself into the lower-left field, and from the upper-right dropdown box find the above script (Sound_Effects), and from there choose PlaySound().
It might be a lot to take in, but give it a shot. Note that this will only give you sound effects when you click, but it’s a start.
thanks alot for explaining this to me and being so patient with me! one of the programmers took some time today to make a script for me, but now i atleast know how to do it myself! i will definetely remember this. i still need to add alot of sound effects after in case i can’t find a programmer to help me within a month. it would be really awesome if you could explain some further about the adding sound effects like i have no clue how to add a sound effect to a specific button (like, after something is opened. not just the click of a button. maybe that is different??), or when landing for a jump for example. but i understand it will be very complicated to explain.
The only reason it’s complicated is that how to do it varies wildly with the context. However, generally speaking, you can use this same method here.
In the method above, you set up a function that actually plays the sound, and you tell Unity to run that function when the button is clicked.
For a less specific case, you can add the code I showed you (and an Audio Source) to any object with a script that needs to play a sound, and insert PlaySound(); in the script where you want it to happen. Just trying to follow this basic instruction set will definitely make you run into problems eventually, but it is a way to get started. Specific questions can always be posted here.
By the way, I’m not sure what you meant by “after something is opened”.
I’m pretty sure you can just do the same thing in that case. Since pressing the button is what triggers the character selection view, can you just play the sound effect in OnClick() like before?