Our scenes have been cool-looking so far — but really, really, quiet. Let’s fix that by adding some background music and some sound effects (sfx) when the coins are picked up by the beach ball.
You’ll need to download a zip file with three MP3 files in it — we’ll be using those in this section. Here’s the link for that zip file:
Right-click that link and then download the file to your hard-drive. Then extract the files from the zip archive and you’ll be ready when the first video calls for them.
The sfx are in the public domain and the music we’re using is licensed CC3.0 from a guy named Carter – here’s a link to the page for the song we’re using: Gel (chiptune) (opens in new window/tab)
Import Audio Into Unity (3:59)
Adding Background Music to a Scene (2:24)
Sound Effects on Prefabs (7:19)
At the 4:50 mark in this video I type a line of code that is no longer valid in Unity 5.x — however, if you type it as shown, save the file, then switch back to Unity, it will see the “old style” code and offer to do an API Update. Let it do that and you’re good to go. When you go back to that source file you’ll see the change that it made.
Below on this page you’ll see more info about this, including the code with the correct line.
Trigger Audio with Invisible Game Objects (3:30)
Teensy Weensy Code Change!
I screwed up in one of the previous videos where I show how to disable the game object renderer — the code I used is different in Unity 5 and I was using Unity 4 for that video.
The good news is, the code below has the correct line all ready to go (and the deprecated line is commented out, but there, so you can see what changed).
The second bit of good news is that if you put the old way into Unity 5 it will tell you exactly how to fix it, or even fix it for you.
Pickup.js (new version)
Back to the Beginning 2D Game Development Dashboard