Unity How to make a Main Menu 2019

Technivorous 3d Printing
33 followers
Sep 3, 2026
Learn Unity! How to make a main menu. in this short tutorial you will learn the basics of making a working menu with the Unity ui!
All right, so first thing we're going to do to make our main menu here is going to be to add a
canvas. We're going to do that by adding another object, and that's this text mesh pro ui.
If you don't have that option showing up, what you need to do is go to package store
under window. Okay, and then if you click all packages, built-in packages,
in project. Okay, there's this one right here. It says text mesh pro. It might say install up here.
If it does, click install. You're going to want to wait for it to install, and I'll show you why,
because then it'll give you this option, and we are going to use this option. I'm going to click
import. Okay, that's done, so let's go up here where we can see it. Next thing we're going to
do is grab our main camera, switch from a skybox to a solid color. We'll do something like this
for now. We go into game mode. You can see this is how we're looking at the moment. Pretty plain
Jane. Go ahead and change this to title. Still looking pretty plain. I have this file I made.
This is 320 by 320, a little bit of a gradient, and I'm going to use this as a background for a
button, so you'll see how that's done here in a second. The other thing that I want to drag
into my scene here is going to be a font, and you pick any font you want. I'll do this one,
because why not? Works best with true type fonts. I don't think the open type fonts work as well,
so then the next thing you're going to do is, since we have our TextMesh Pro
imported, you need to go to window, TextMesh Pro, font asset creator.
Up here where it says source font file, you're going to click on the font that you imported,
and then click generate font atlas. This takes a couple minutes. There's some processing involved.
It's going to make a specialized bitmap based off that font. It's going to use that bitmap to
basically populate your menu or your UI text items. I'm going to pause this for a second
while it loads. Bear with me. All right, so it's all generated. The next thing we need to do is
make sure I hit the save button, so hit save. Save it as SDF file. That's fine. All right,
now we go back to my TextMesh Pro, and right here where it says font asset,
click the little circle. We'll kick that over to Fulcrum. Look at that. Game title, it says.
Now, a couple notes. Color gradients are pretty dope. That's just using the different color
gradients. It's on four corners mode. There's horizontal, there's vertical.
Switch to horizontal, switch to vertical, and then set it back to single, and I actually
let's do blue, and then because there's a blending option down here, this is where you're going to be
editing most of the font effects, and if I add, say, yellow, it turns green because it's blending
the two colors. If I set the color back to white, I can also do a blend of the vertex color, the
color, and the face color. We're going to go with... Actually, we are going to use a gradient.
It's going to be a very, very simple gradient. Four corners. It's going to be tinted out on two
corners. A little bit of color will work for now. Very simple. There's lots of options here, guys,
so don't feel pigeonholed into what I'm doing. I'm just basically showing you how everything works.
Softness will blur the edges a little bit. Dilate will expand them out
or in. I'm setting both of these to zero. You can set a texture. That's perfectly fine.
Now my face color is going to kind of be tinted by that gradient, which is fine, too. I kind of
like it. Let's do an outline. The outline is going to be a float value, so anything between
zero and one, we're going to say 0.1. We're going to give it a little pop. Underlay, also
something I like to use quite a bit. I normally set it to the left and down. Actually, we're going
to kick over to something a little more jovial here so you can see. Something a little brighter.
I think I like it about right there. In our scene, this is what you see,
but this is definitely not ideal. It's kind of small text, and for the title here itself,
we want something a little larger, so we're going to go to 72, and then we're going to center it
horizontally as well as vertically. That'll give us a little space above and below.
Back in game mode, this is what we're looking like, so not too bad so far.
The next thing we're going to do is add a button, and
we're going to delete this text, and on the button, we're going to add another
text mesh pro. We can't see it right now because of the color, but go in, select our font,
there we go, and then we're going to adjust this accordingly. I always mess up because
the yellow box will change size with the other box, basically, so the only thing
to adjust the size of is the bounding box, the blue circles. I'm going to adjust this
just a little bit more so it fits there. Okay, so now I have my text mesh pro. Change this to say
new game, and then we're going to go in our button, and we're going to change
our button picture to a sprite. Okay, so now we have our basic button here.
Now we're going to copy and paste. This text mesh will change, and the other one
open up as well. Okay, so this is basically the looks of our menu right now. I am not a big fan
at the moment of the color of this box, so give me just a second. I'm going to go ahead and change
that bitmap so you can get something a little bit more pleasing. All right, so I've grabbed this
other graphic. Actually, I grabbed a couple and tried them out, and this is something that you're
going to be doing, especially when building a menu for your own game, is you're going to try
a couple of different things. You're going to mix things up, try new graphics, try new pictures,
get a feel for the whole overall aesthetic, and see what you can find that blends into that. Now,
since my scene is basically empty, black blends in just fine, and I wanted to show you I did do
two more things. You go to... I'm going to click on each of these buttons where it says
highlighted color. It doesn't really matter what color. You're just going to pick a color,
okay? Let's see, so I'm just going to use this same color, so ctrl-c,
next button, and you can paste, copy and paste. Okay, now let me show you what we just did. So,
right now, I'm not actually in the game, so it's not doing anything, but in here, in your menu,
when you're playing, when the option becomes highlighted, it will pop up that color.
I don't know what I did to the second one. Why it's not working. Let me fix it.
Now, it's important to note that the reason that these are showing up the way that they are,
I have that highlight color set to blue, so that's why when I enter them, they select as blue, but
there we go. That's much better. So, now, if I were to change my normal color to yellow,
see how this one's yellow already, okay, and then when I highlight it, it's still going to
change to blue. It's not going to blend those two colors. Undo that. So, right now, and then
when we click it, it's going back to normal, and that's because we haven't set the pressed color
yet. So, let's see, pressed color, green. We're going to copy and paste this color as well, so
control C. Now, and I made these, the contrast in these colors pretty bold. A lot of times with
buttons, it's going to be two tones of the same color or grays. You get a lot more subtlety that
way. So, now they all highlight blue, and then if I actually select one, it'll flash green,
and you can change that to whatever color you feel is appropriate. So, I'm going to pause the
video here because pretty soon we're going to be going into some coding, and I need to make sure
that I have Visual Studio open. So, one second, we'll be right back into the video. All right, so,
I also dragged this wave sound in here. I just threw up my other resources. In order to instantiate
this, you're going to go to audio, audio source, and then basically this is your audio clip. So,
you'll drag and drop and turn my volume down. Now, when I hit play, I'm going to wait for it.
Let's do this some more. I'm going to maximize on play, and I'm going to change this to loop, okay?
We got a little bit of our menu going here. Not too shabby. Now, it's important to mention that
this is a wave file. I just did a search for wave loop free download. You can find tons of
resources that way. Most of the time, when you find them on a website such as that, it'll tell
the licensing requirements or whether or not you need to add an attribution, which means
giving the creator credit. This is just a freeware, free to use. It doesn't have any
license. It's just free. So, I just grabbed a little loop sample. The other thing that I pulled
in, I just did a quick YouTube graphic search on backgrounds, and I pulled in this image,
which I'm going to put on my canvas, but apparently, I need to right-click canvas UI image,
and I'll drag and drop that. Sprite, really? Okay, fine. Sprite, apply. Now, we can drag and drop
that bad boy, and then go back into my scene, resize it, and actually, since it's on our canvas,
it's rendering in the way, I think. So, in order to push to the back, we got to move it up.
So, let's see how we're looking now. It looks good. It's kind of plain Jane, though.
I like this background effect. So, we're going to leave it for now. Later on, maybe we'll see
if we can create something like that that kind of moves. Now, it's going to be time to get into
coding, and as you see, I opened up my Visual Studio, and I have a script here called main menu.
All right. So, I'm getting sick of looking at this. It makes me feel a little better.
I make constant adjustments as I go, just because as the look's kind of changing,
you're wanting to evolve with it, you know. We'll go with that. So, now that we have our
stuff all set up there, what we're going to do is we're going to go in here.
We're going to get rid of this. Get rid of the start. Get rid of the update. Okay.
We are going to need to add a using statement. Now, I know it looks like this is already in here,
but I promise you it isn't. All right. So, now that we have a scene manager, let's do public void
new game. Scene manager dot load. We're going to be loading scene one in this method,
and this will all make sense here in a minute. I like to stick to convention here. So,
load game and options. So, we're going to change this to, that's also going to be one,
and okay. So, file. Save all. Go back into your unity here. It's also important to note that
right now, if we put this script on and we attach it properly, which we are about to do,
it's not going to do anything because I don't have any other scenes yet,
but I'll show you how to set those up in a second. So, there we go. Create empty.
Rename this main menu script. Okay. And we're going to drag and drop our main menu script
onto it. Okay. Next thing we need to do is go to our first button. Since list is empty,
we're going to add, put the little plus here. Not two of them, just one. Then drag and drop
your main menu script into there and go to main menu.
Made these public, so they should be showing up. We should, in that little menu, I was just
looking at, we should have a new game, a load game, and then options right here in main menu.
Oh, it's saying runtime only. We need to change this to editor and runtime so we can actually
find the function. All right. Sorry about that. You guys shouldn't have any problems
doing what I was just trying to do. My computer is kind of running out of memory because I had
too much stuff open. So, I closed a couple of programs and now we seem to be functioning
properly. As you can see, I can select my button. I can go in here under main menu
and I can go to new game and I'm going to set them all. The second button is my load game button
function will be load game. Actually does the same thing as new game at this point.
Once again, drag and drop your main menu, main menu. That'll be options. Then I need to go to
build settings. I need to add open scene. It's a sample scene right now. It's actually going to be
my main menu scene. We can rename it later. But this zero here denotes what we're going to use
to open it. So, now that I've done that file, hit save as. This should allow me to save as a new
scene that we will call game scene. We're going to delete this and this and take this button
back into my scene mode so I can move it. Take that button and put it down here. Select the text
type in main menu. We're going to grab this text, type main game scene,
file, save. We need to add one more script here. It's going to be called go to main menu.
We're almost done here guys, so hang in there with me. If this video is helping you at all,
don't forget to hit the like button, subscribe to my videos. I'm going to be doing a lot more of
these one shots in the future because as much as I like doing the in-depth long tutorials where you
see beginning to end the game making, this is actually really, really neat for finding the
things that you need to do just really quickly. Like say today I'm on task, I want to make a main
menu. That's exactly why I made this video. So, like I said, like, subscribe, leave comments down
below about other videos you'd like to see. I always like to see those. In this one, we are
going to leave the start and update methods because we're going to be adding an input button that will
also return us to the menu, but we are going to need a public void go to main menu. This is our
main method. Again, try to stick to convention and then I'm going to add that same using statement
again. We're actually going to use it again twice and it won't let me, there we go, couldn't be the
same as the class. So, now go to main menu is going to be scene, manager, open scene, oh no, excuse me,
load scene and remember I showed you our menu is scene zero. So, the other thing we want to do is
we're going to go to update. This is going to be a key input. We're going to say if input dot get key.
Okay, now we have to pick the key and to do that we say key code dot and we're going to use escape.
Okay, so now if that key is pressed, the escape key, we are going to return as well. So, file,
save all. Okay, now we still have our main menu script in here and we don't need it in this scene.
So, I'm going to delete that. I'm going to go add another empty. All right, we're going to take,
we're going to rename our empty object, go to main. Okay, now we're going to go back into our
main menu and we are missing a reference. That's fine because we deleted that.
So, we're going to grab our go to main, drop that in there and we got to add our script to that or
it won't do anything and we're just going to hit our go to main menu. Okay, now we need to file,
save. Okay, that's saving our main game scene. Like I said, we're almost done. We got to change
one more thing. First, we need to add open scene. That makes this scene one. Remember when we said
load scene one. Okay, then the last thing we're going to do, just to make it apparent that we've
done something, when we change scene, excuse me, that's not an S. There we go. Now we need to hit
file, save as, go into our scenes again and option scene. Okay, and the last thing we need to do
before launching this and testing it out is add this last scene because we had a reference to two
as well. So, that's our option scene. So, one more time, let's double check our logic here. Looks like
everything's sewed up. Both of these are going to open the same thing because we're not actually
loading a game. We don't have any data to load. So, file, save just to be sure. And the difference
here is, and the reason I did it that way is because we created our first scene. We saved it
under the scene it already was, sample scene, and then we altered a couple things and saved the same
scene as our new game scene. So, instead of creating a new scene and having to go in and try and
recreate everything, we created multiple scenes from basically the same template. We're going to open
our sample scene and should be able to play and check out our menu.
Highlights are working, new game, main game scene, main menu, load game takes us to the game scene,
the same scene, options takes us to the option scene. Now, also if I hit escape on my keyboard,
it'll go back to the menu. You can set that input. Let me shut this noise off. You can set
that input to take button clicks, mouse clicks, taps, pretty much anything. So, that's going to
be it guys. This is how to make our main menu. We're going to wrap it up right there. I hope
you enjoyed this video. Like I said, don't forget to leave a like and hit that subscribe button. We
got a lot more in the future. If there's anything in particular that you want to know like Unity
one shot wise, we're going to do a ray casting one, one on making terrain, stuff like that. So,
ideas, suggestions, drop them down below in the comments. I'm pretty sure that I'll
be able to get to all of them eventually. Yeah, like I said guys, tell a friend,
hit that like button, hit subscribe, hit the notification bell so you get notifications
when we do future updates for future tutorials. And that's going to be it. Technivorous out.
