Always Sound on Mouse Down

Hi Guys, I’d like to ALWAYS play a click sound when I left click with the mouse. Until now I used audioclips but this is getting pretty complicated and messy. Is there a way to add a script to the mouse itself and add the sound and then play it whenever I click?

Thanks

Why do you need to add the scrip to the mouse? Add it to any object in the scenery. Have the script simply check during Update() if there is a mousedown, and if so, play the sound. That’s pretty much it, or am I overlooking something?

You can’t add a script to the mouse. But you can add a script to an empty game object and check in its Update method for Input.OnMouseDown. There you can play a sound. Note: if you have multiples of said gameobject or script instances you will play the sound several times. So maybe a singleton would be suitable for the script. And I would suggest to count the time since the last playback and constrain it to maybe 0.5 seconds as playing the sound with high frequency may sound weird.

thank you both. the problem is that I need a collider for OnMouseDown (if I am not completely wrong) and when putting this collider over my scene, it interfers with basically everything else - but I might oversee something? otherwise the solution is ofc working but I am not sure how to solve this…?

You don’t need a collider when you check Input.GetMouseButtonDown in Update.

1 Like