Hello guys.
Welcome to the video.
So in this one we're going to make main menu.
And we're going to start with simple.
We're going to make a scene with an animated background.
And later on I'm going to show you how to add buttons.
So as you might know everything we have in here, it is uh, packed into a scene and here we have the
scene itself.
It is saved with name of simple scene.
You also can make a new one.
Let's go to create.
Scene.
Scene, and let's call it main menu.
Now if you go inside of main menu, you'll see project is empty.
It doesn't mean you lost everything.
It just means you switched the scene and everything is here.
Just saved under the different scene setup.
Now we need to go back to main menu scene.
And here we need to do setup that we'll use to start the game, to continue the game or to work with
settings.
And I want to begin by creating animated background.
Let's just make some platform over here so we can see something in the game window, because as of now,
it's not as pretty as I would like it to have.
We're going to go to Tile Palette.
Or actually, we need to make new, uh.
Tile map rectangular.
I'm going to call it ground, although it's not that important.
And here we just need to take the platform we want to have in the main menu and draw it like so.
Okay, I think I want to zoom out the camera just a bit.
So I'm going to select the camera and I'm going to do size eight.
Okay, now let me take this again and draw something like this.
Later on we're going to extend it to the right.
But as of now let's just work with this and give me a second.
Yeah, probably something like this will do.
Fine.
Now we need a background and we're going to do animated background.
We're going to do that with the help of a 3D object.
And we just need to go over here and draw one set of a background.
Just so we have a reference for the setup we are about to do now.
So I'm going to place it here.
And now we need to make 3D object.
Then we're going to put a texture on this 3D object with the image of a background.
And then we're going to just repeat that image on the 3D model.
And because of that it's going to look like it's just spinning like it's moving endlessly.
Okay I know it sounds confusing, but let's just do it.
It is very easy to do.
Uh, let's make 3D object quad.
And we need to make it much the size of a background over here.
So I'm going to place it somewhere in the middle.
And I'm going to try to increase the scale.
Okay, so it's something like four.
Nice.
Now we can see two problems here.
One of them, it is in front of the platform and we want it to be a background to make it, uh, stand
behind the platform.
We need to switch to 3D view over here, and we need to select camera to see where camera looks.
Camera looks there.
So we want this object be behind the platform.
For that we can just take the quad and move it on the z axis like so.
Now we can switch back to 2D.
And now it is behind the platform.
We just moved it in a 3D space.
So we have background ground and camera.
Nice.
Let's go back to 2D.
And second problem is the color.
We don't want to have color just like that.
We want it to have texture that we use for backgrounds.
So we're gonna go ahead to asset material.
And over here.
We need to make new material.
I'm going to call it just background for now.
That is enough.
And I think this is the extra we don't need it.
So I'm going to I don't know why I have it.
Let's delete it.
Nice.
Now let's go to the quad game object.
Let's name it as background.
And let's drag material over here.
Very cool.
Now we have material.
And if we want, we can, for example, change color for it or do anything else we want with it.
What we want to do is to change material type to unlit texture.
Now it is just white, but it's only because it does not have any texture over here.
We need to go to graphics background and let's practice with the yellow one.
So I'm going to just drag yellow to this field over here.
Now it's basically repeating the background we have.
But not only that, now we can use this material to animate background.
Uh, if we use offset over here, if we increase it, then you'll see that this image is going to move
away like that.
Unfortunately for us, if we move it, it looks weird, but it's only because we did not change.
Rap mode over here because we define how image will wrap the 3D model if we use it as a texture, and
we wanted to change to repeat.
Let's hit apply.
And now if you go back to background and change offset, you can see image is repeating itself and it
looks like it's moving around.
Yeah.
Very cool.
Now let's make a script that will move it around.
And then I'm going to show you how to use it with different colors and also how to make it bigger.
So it will take entire space of the screen.
Let's go to scripts and let's make Monobehaviour script.
Animated background.
As you've seen just now.
Let me do close all by this.
As you've seen just now, I'm using material and I'm changing parameters of the material.
So our goal is to get access to this material.
And we can do that through the mesh renderer because mesh renderer has material over here.
So what we need to do in this script is to get component of a mesh renderer, and then get access to
the property of a material.
Let's go back to script.
And over here I'm going to do private mesh renderer.
Mesh.
Then we're going to open a wake and do mesh equals to get component of a mesh renderer.
And also we want to have some sort of serialized field.
Private vector two movement direction.
Then in the update let's open update.
We want to do mesh main um I mean material main texture offset because we changed offset and we're going
to add value to the offset all the time.
So we're going to do plus equals movement direction.
And we want it to be frame rate independent.
And that's why we're going to multiply this by time dot delta time okay.
Now let's save this.
Let's go back to unity.
I'm going to put script on the GameObject and we have movement direction over here.
And let's just go to play mode.
So now nothing is happening.
But if we go over here and give some value on the Y, for example, you're going to see how background
is moving.
We can make value bigger so it's faster, but we don't need it that fast actually.
Yeah.
Let's use 0.5 maybe.
Because of the texture itself.
It looks like it's moving down and left, but actually it's just moving on the Y.
We can easily check that by changing texture over here.
Let's go to Graphics background and let's choose any other texture.
We just need to select them all and change wrap mode to repeat.
Let's do apply.
And now if you put any other texture this one for example, it looks like it's moving from top to bottom
right.
Very good.
Now before we make background bigger, let's use all of the colors on the background so you can easily
switch between them without going to graphics folder.
Let's go to Animated background.
And at the top I want to make public enum background type.
And here we need all colors we have.
I'm just going to go to Asset Graphics background.
Like that.
And I'm going to type blue.
And yellow.
Nice.
All of the colors we have.
Now let's save this.
Let's go here and let's make a header for color.
Then I'm going to make serialize field private uh background type background type.
And we want to have array of textures.
So we can choose a texture that we want.
I'm going to do private texture 2D textures just like that.
Then let's make a method private void update um background texture.
And inside we're going to do mesh material.
Main texture equals to textures.
And for the index of the texture by the way should be an array like that.
And for the index of the texture we're going to use background type.int.
So we convert uh enum to the integer just like we did before.
And we give it as a value to choose the texture we want, and we assign it to the main texture over
here.
Now we can do this in the awake just when we start the game.
Update the background texture.
And also we can go here and make context.
Menu.
Update background in case we want to change something in the editor, or maybe just in the play mode
itself.
Nice.
Now let's go back to unity.
Let's take this background.
Open textures and let's assign them one by one.
One green, pink, purple and yellow.
Just make sure it is in the same order as you have here in the enum.
All right.
And we can choose any color you want.
For example, I want to try green and you can go to play mode.
And it will change the texture to green.
Nice.
We also have default offset uh, at 13.81.
Let's remove it.
Let's make it zero.
And let's go back to game mode and see this.
Okay, it works.
And if you want, you can give it some movement over here.
Very nice.
Now let's make the background bigger.
How can we do this?
Well, we know that this game object is four times bigger than just a tile we have over here.
So if I wanted to make much bigger, probably I can just use scale not of four but of 40 like that.
Now it is much bigger, but the issue is that texture is stretched on the entire game object.
What we can do is go to material over here and change tiling from 1 to 10 by ten.
And now it's going to be just nice and pretty, just like we need.
Now let me go ahead and erase what we have over here.
Gonna switch this off.
Arrays this.
And I want to change the background to something else.
Green is fine.
Let me click Update Background or we cannot do it because we don't have a component of a mesh, so we
cannot do it in the editor.
Okay okay okay.
Let me.
Let me do this.
If mesh equals to null then get component of mesh renderer like that.
No, no mesh equals to get component of a mesh renderer okay, this should work in the editor.
Let's try again.
Update background.
Yeah, works for us.
Okay, nice.
Now let's set Y speed 2.1.
I want it to be really slow and let's go to play mode.
And we have animated background.
We have nice menu.
Now we can proceed with the development.
I have a couple of more nice ideas that we can use to make menu pretty.
I'll see you in the next video.