Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Unity Basics!
You have completed Unity Basics!
Preview
The time has come. After quickly adding some background music, weβre going to build out our game. Congratulations, game devs!
Unity 6 Documentation
- Introduction to the Audio Source Component
- Audio Listener
- Platform Development
- Player Settings Window
- Build Profiles Window
Game Asset Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Welcome to the final video of this course.
0:00
There's one small thing I'd to add
before we build the game out,
0:03
and that's background music.
0:06
Playing a silent game is pretty awkward,
so let's fix that.
0:08
Inside of this audio folder
that came with the downloadable files,
0:11
we have this audio track.
0:14
I got this from one of my favorite
websites for game assets, opengameart.org.
0:16
It has a CC0 license,
so it's completely free
0:22
to use and edit, and it was created
by a user named MintoDog.
0:24
So thank you, MintoDog. You're awesome!
0:28
I placed some links in the teacher's notes
to a few of my favorite sites
0:31
to get assets to play with.
0:34
Just be aware that not everything is free,
and not all free
0:36
assets can be used without giving
some kind of credit to the creator.
0:39
So always check the license type
before downloading assets
0:43
to save yourself
from any kind of backlash.
0:46
Unity also has an amazing asset store
with free
0:49
and paid assets that you can download
and import straight into your game.
0:52
You can find it by going to Window >
0:56
Asset Store, and it'll open up a new
tab in your default browser.
0:58
So just like when we dragged an image
into our hierarchy
1:02
and Unity knew exactly what to do with it,
the same goes for audio.
1:05
For adding sound effects
in specific moments of your game,
1:09
that'll of course take a little more work,
1:12
and that's outside
the scope of this course.
1:14
But for our background music,
1:16
we can simply drag this audio file
right into the hierarchy.
1:18
It creates a game object for us with an
audio source component already attached.
1:21
This is one of the tools used to work
audio into your games with Unity.
1:26
Let's rename it to Background Music.
1:31
To hear audio in your games,
you need an audio listener component
1:37
attached to something, and by default,
our main camera already has one.
1:40
This will essentially act
as if the speakers were right next
1:44
to the camera, front and center,
so we're all good to go.
1:47
You'll see this audio resource property
has a play on awake checked by default.
1:50
This is great for our case
because we want the music
1:55
to automatically start
when the scene starts.
1:57
Let's also check this loop
option to be enabled.
2:00
This will cause the music
to immediately start over once it finished.
2:03
The only other
2:07
option we need to worry about
is the volume. I'm going to turn mine
2:08
halfway down to 0.5 and test it out,
2:11
but feel free to adjust yours accordingly.
2:14
And just like that, we have background music.
2:22
Okay, before you build a game out,
2:32
it's very important to go through
all of your game objects and scenes,
2:33
if you have more than one,
to make sure everything is set up.
2:37
Once we start building, it's going
to take the game in the state it's in,
2:40
and it can take a while to build
2:44
depending on the size of the game
and your machine's capabilities.
2:45
The only thing we need to worry about
2:49
is our game over menu
being disabled initially.
2:50
There is nothing worse than building out
an entire game to realize
2:53
you forgot something like
this as soon as you play it afterwards.
2:57
Trust me.
3:00
So to avoid this issue,
let's add a line of code
3:01
to make sure this menu is always disabled
when the scene starts.
3:03
That way,
3:07
we don't need to worry about remembering
to disable it before we create our build.
3:08
Let's open up the GameManager script.
3:12
In here, we already
3:17
have a reference to this menu object
since we're enabling it below,
3:18
So all we have to do
is the opposite of what we did earlier.
3:22
In the Start function,
after we set our time back to 1,
3:25
let's write gameOverMenu.SetActive
3:29
and this time, we'll provide it false.
3:33
Cool, let's save this.
3:35
I'm going to keep this game over menu
3:39
enabled now and enter play mode.
3:41
Cool, it's not there.
3:47
we lost it appears and it's gone again
when we start.
3:50
Perfect!
3:53
Remember,
if you're working in the scene window
3:55
and this menu is getting in your way,
you can always toggle its visibility
3:57
with this eyeball icon in the hierarchy.
Alright we're looking good!
4:00
Let's learn how to build our game!
4:05
Let's make sure to save our project
4:09
and head to Edit >
Project Settings and click on Player.
4:10
This is where you can adjust more
of your settings for your project
4:16
once it's built,
the file name, icons, etc. I'm
4:19
not going to worry about too much here,
but just for fun, I'll change the icon.
4:23
Let's expand Icon
and check this Override button.
4:27
and let's just drop an image of Mike
4:31
in here.
4:33
The resolution isn't perfect, but oh well.
4:38
You would get an icon with a Unity logo
if you don't overwrite it here,
4:41
so you don't need to do this.
4:44
It just makes it a bit more fun
and personal.
4:46
Also, I need to point out,
my computer setup
4:49
is using a 1920x1080 monitor,
so when I build this out and play it,
4:52
it'll go full screen and look perfect,
as that's our canvas and camera sizes.
4:57
If you're using a larger monitor,
especially one of those ultra-wide
5:01
ones, or something
that's not a 16x9 aspect
5:05
ratio, you'll want to
make another adjustment here.
5:08
Open up this Resolution and Presentation
option and unselect this Default is Native
5:11
Resolution here, and ensure
that 1920x1080 are in these fields.
5:16
Awesome.
5:22
Now let's head to File, Build Profiles.
5:25
Your scene should be listed here still
unless you've removed it by accident.
5:28
If so, just click this Add Open
Scenes button and it should reappear.
5:32
Next, make sure that the operating system
5:37
that you're using is active,
which it should be by default.
5:39
I'm on Windows, so I'm good to go.
5:42
Now, don't follow me quite yet.
5:44
I wanted to show you
that it'll give you a warning
5:46
if you try to save it
directly to your desktop.
5:48
And in general, it's
better to save your builds outside
5:51
of your actual project folders.
5:54
So I'm going to create
5:58
a new folder named Builds
inside of my Unity Projects folder,
5:59
but feel free to place yours
to your liking.
6:03
I'll head back to the Build Profiles
window and I'm going to click
6:12
Build here and tell it
to save it to my new Builds folder.
6:15
This is going to take some time,
so you can pause me here and return
6:19
once yours is completed too.
6:22
Okay, I hope yours went successful.
6:27
If there were any errors,
you can do what I do and copy
6:29
and paste them into a Google search,
6:31
but with this small game,
you should have been just fine.
6:33
Here on my desktop, in the builds folder,
I've got our flying
6:37
Mike game with the icon. Awesome!
6:40
Let's test it out.
6:42
Here's our default Unity splash screen.
6:48
The game over
menu is disabled at the start.
6:53
We've got our music in the background.
6:56
The score is increasing.
6:58
There's the game over menu.
7:02
Restarting is working,
7:05
and we can actually test our quit button
now too.
7:07
Yep, that closes off the application
perfectly.
7:13
Way to go.
7:16
If your game is looking
wonky when playing it,
7:18
you may need to go and adjust
that native screen size option
7:20
I mentioned earlier
in the player settings.
7:23
If you've
7:27
stuck with me this far,
I congratulate you.
7:27
Whether it feels this way or not,
you're a game dev!
7:30
We had a game
plan, started from complete scratch,
7:33
created and built out a playable game.
7:36
You should be extremely proud of yourself.
7:39
Now we've barely scratched the surface
on all these topics in this course,
7:42
so if you enjoyed this
and would to see more, please let us know.
7:46
I know for a fact the next time you play
any of your favorite video games,
7:50
you'll be realizing
how much work went into creating them.
7:54
You'll probably also start playing games
and seeing things
7:58
that make you think, hey, I
wonder how I can get that into my game.
8:01
Anyways,
8:06
I hope you had as much fun with this as
I did, and I hope to hear your feedback.
8:07
Until next time, take care,
everyone, and happy gamedeving!
8:11
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up