Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

People seemed to really enjoy the post in which I shared my scripts to take marketing screenshots, so let's share another script that I made a long while ago and I always import into every new project I make, my SoundManager script!

It's a thing I've seen lot of necomers struggling with, they come up with this weird solutions involving lots of audio sources all over the place tangled in the code, then whenever they need to change an audio clip it becomes this huge problem. I've heard more than once from sound designers in game jams that they made way more sounds but the programmer didn't have the time to implement it into the game…

Well, if that sounds like something you've experienced, this might help you!

This is the system I use to implement sounds in my games, it allows for:

  • All of the sounds are prefabs inone folder, so it's easy to know where to go to change things later.
  • Each prefab, which I call "SoundGroup" is a group of audioclips, from which one of them will be picked and played at random. A SoundGroup can be one single audioclip if you so desire. This makes having random sounds for the same action really easy.
  • You can also pick a random pitch range for the soundgroup to introduce even more variation.
  • If the SoundGroup is marked as music, instead of picking a random one it'll play them in order as a playlist.
  • For easy implementation of per-level-music if you have a soundgroup on the "Resources\SoundGroups" folder with the same name of a level and that level is played, the SoundGroup will start playing automatically.
  • It uses a built-in pooling system to reuse the SoundGroup gameobjects instead of destroying it every time, that way there's no garbage collection mess while the game is playing :D
  • It uses playerprefs to store and use volume preferences, volume preferences (0 minimum 1 maximum) are then multiplied by the volume you picked on the prefab's audio source :)
  • This part might annoy some programmers but I find it way easier for me… You can call the sounds in the code by using the prefab name (string). However, for the programmers that hate doing that kind of stuff, you can call it with the prefab.
  • I commented the hell out of this script D:
  • Calling it is as easy as: hurtSFX.PlaySound();

Well, that's about it :D I find it really useful for my projects, so hopefully it'll help you on yours as well, you can download it here.

I also recorded a quick video showing how to use it.