For all Unity developers and developers-to-be, both beginners and professionals!

Post tutorial Report content RSS feed How to change the background music? (one soundtrack)

A simple tutorial on how to change the soundtrack / background music played in Car Tutorial project.

Posted by feillyne on Oct 21st, 2010
Basic Sound Effects.

In Car Tutorial project, it's quite simple.
1. Open CarEdu (/CarTutorial) project, find and expand directory in Project tab:
So you see CarTutorialSong.mp3 file
2. Find your .mp3 file, then drag it into the directory where CarTutorialSong is
3. Untick 3D Sound, tick Decompress On Load, click Apply
4. Select Car object (the main parent object, not its child parts), scroll down to Sound Controller (Script), then change Background Music by clicking the circle next to the name, and set it to your mp3 file.

That's pretty all. This tutorial shows only how to replace one soundtrack with another. If you know more about JavaScript and coding, to make the game play more soundtracks you'll probably need to check this piece of code below:

backgroundMusic = gameObject.AddComponent(AudioSource);
backgroundMusic.loop = true;
backgroundMusic.playOnAwake = true;
backgroundMusic.clip = BackgroundMusic;
backgroundMusic.maxDistance = BackgroundMusicVolume;
backgroundMusic.minDistance = BackgroundMusicVolume;
backgroundMusic.volume = BackgroundMusicVolume;

157-163 lines, SoundController.js in Scripts/JavaScripts (note the backgroundMusic variable declaration in the line #50).

Post a comment

You are not logged in, your comment will be anonymous unless you join the community. Or sign in with your social account:

Oct 31, 2010
Open to all members
Send Message
Join this group
Group watch
Start tracking
Related Games
CarEdu Racing
Related Engines
Unity Commercial Released 2005
Related Groups
Indie Devs
Indie Devs Hobbies & Interests with 1,281 members
Unity Devs
Unity Devs Hobbies & Interests with 1,445 members