Soundcard Script – a useful trick

So I am not setting myself up as some kind of expert on Sound or Scripting but one thing I have seen alot in games across multiple Ludum Dare is a lack of sound effects, my own games included. Its easy to overlook in a 48-72 hr time frame especially for the many of us who aren’t musically minded. Its also easy to write off as not being important or as important as other areas of the Games development. In truth the difference sound effects and music can make in a game is huge, the instant feedback you get from hearing a button beep or an explosion go boom can be a key part of immersing in a game and can really help notch up an extra star in the scoring. So I have been there, telling myself that I will add the sound later once I have nailed the key mechanics down, or got the art done or one of the many tasks we set ourselves only at the 47th hr to not have the time to go through and add in the code and sound effects, especially when a project has spiralled out to 20+ scripts with as many different things that need it.

 

This time I plan to handle things very differently and the code I will be using will get created at the beginning and look like this.

soundcard

So rather than having multiple audio sources attached all over the place I am creating 1 & putting all the music and sound effects in one place. A bonus to this is I don’t need to work out every sound effect at the beginning of the project. All I need is a place holder beep and each time I need a new sound effect I can add new entry into the sound effects array. Using code as I go an anything that sets of a sound i just add in

Soundcard.Soundselection=?;
Soundcard.Playsound();

or

Soundcard.Songselection=?;
Soundcard.Playsong();

and when I reach that 47th Hour all that’s needed is that I drop the sound effect/music I am using for each one into the array in the editor (Unity user :)).No extra coding, no worrying about conflicting sounds, no adding multiple audio sources.

So I thought in the build up the LD35 I would share one of my solutions to a problem that I have faced & i thnk alot of other LDers have to.

Feel free to tell me my code is dumb and awful and wrong in the comments :)