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

Report article 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:
/Sounds/Sound/
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:

javascript code:
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
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Established
Oct 31, 2010
Privacy
Public
Subscription
Open to all members
Homepage
Unity3d.com
Contact
Send Message
Email
Members Only
Membership
Join this group
Group Watch
Track this group
Tutorial
Browse
Tutorials
Report Abuse
Report article
Related Games
CarEdu
CarEdu Single & Multiplayer Racing
Related Engines
Unity
Unity Commercial Released May 30, 2005
Related Groups
Indie Devs
Indie Devs Hobbies & Interests group with 1,131 members
Unity devs
Unity devs Hobbies & Interests group with 1,243 members