How do I consolidate common sound effects?

Hi there.
I have multiple “coins” in my game, which all share a common “Coin.cs” script.
These coins have 5 different Public sound effects attached to them. Each time I decide to change a sound effect, I have to re-link the public sound to each of my different types of coins. Is there a way to establish one batch of AudioClips that will relate to all coins? I tried creating a “Sounds.cs” script, which will hold AudioClips for my different interactions (e.g. “metal_collision”, “wood_collision”, “jackpot”, etc.), attached it to my Coin, and used getComponent() inside of my Coin script, but something isn’t referencing correctly. (“Object reference not set to an instance…”)

What’s the best way to create a public sound library I only have to populate manually once, and can then reference from any object?

Thanks!

Do what it sounds like you were trying with your Sounds.cs script. Have a central object in your scene with a script that has the correct audioclip reference, and all of your coins get the audioclip from there. As far as your object reference error, you’d need to figure out what you aren’t setting correctly.

I believe there is a ‘LoadAll’ function that deals with exactly this sort of problem in Unity and you can even just put all your files into a folder to organise everything, the only catch is you have to use the resources folder.

Is this what you’re thinking of?

If you’re talking about just generally grabbing stuff I think an array is suited for this.

Came across this when I was looking to randomly play music in my game.